[英]Get order id from cart id module prestashop 1.6
controller/front/validation.php 控制器/前/ validation.php
<?php
class Paytr_CheckoutValidationModuleFrontController extends ModuleFrontController
{
public function postProcess()
{
$this->display_column_left = false;
$this->display_column_right = false;
$cart = $this->context->cart;
$total = $cart->getOrderTotal;
$currency = $this->context->currency;
$customer = new Customer( $cart->id_customer );
if ( !Validate::isLoadedObject($customer) )
Tools::redirect('index.php?controller=order&step=1');
//$this->context->cart->delete();
//$isOrderX = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' SELECT * FROM '._DB_PREFIX_.'orders WHERE id_cart = '.$cart->id);
//var_dump($_POST);
//Tools::redirect('index.php?controller=history');
//Tools::redirect('index.php?controller=order-confirmation&id_cart='.$cart->id.'&id_module='.$this->module->id.'&id_order='.(int)$this->module->currentOrder.'&key='.$customer->secure_key);
echo 'index.php?controller=order-confirmation&id_cart='.$cart->id.'&id_module='.$this->module->id.'&id_order='.(int)$this->module->currentOrder.'&key='.$customer->secure_key;
}
}
I need to find order id from cart id. 我需要从购物车ID中找到订单ID。 These are I tried. 这些是我尝试过的。 I couldnt get id_order. 我无法获得id_order。 I was hopeful for Db query. 我对Db查询充满希望。 But it doesnt work I think. 但这不起作用,我认为。
您可以使用以下代码获取它: $id_order = Order::getOrderByCartId($id_cart);
As long as the order is not registered, you can not get "id_order". 只要未注册订单,就无法获得“ id_order”。
If the order is registered and you are sure that there is no better way, you can use the following code to find the latest cart that has been ordered: 如果订单已注册,并且您确定没有更好的方法,则可以使用以下代码查找已订购的最新购物车:
$this->context->customer->getLastCart(true);
this is the problem cause deletes cookie after validate order. 这是导致验证订单后删除cookie的问题。 So It doesnt show id_cart. 所以它不显示id_cart。 So I figure out like this. 所以我想像这样。
$isOrderX = Db::getInstance()->getRow(' SELECT * FROM '._DB_PREFIX_.'orders WHERE id_customer = '.$cart->id_customer.' ORDER BY id_order DESC ');
Tools::redirect('index.php?controller=order-confirmation&id_cart='.$isOrderX['id_cart'].'&id_module='.$this->module->id.'&id_order='.$isOrderX['id_order'].'&key='.$customer->secure_key);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.