从购物车 ID 模块 prestashop 1.6 获取订单 ID
Get order id from cart id module prestashop 1.6
controller/front/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;
}
}
我需要从购物车 ID 中找到订单 ID。这些是我试过的。我无法获得 id_order。我对 Db 查询充满希望。但我认为它不起作用。
您可以使用此代码获取它:$id_order = Order::getOrderByCartId($id_cart);
只要没有注册的订单,就无法获得"id_order"。
如果订单已注册,您确定没有更好的办法,您可以使用以下代码查找已订购的最新购物车:
$this->context->customer->getLastCart(true);
这是导致在验证订单后删除 cookie 的问题。所以它没有显示 id_cart。所以我是这样想的。
$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);
controller/front/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;
}
}
我需要从购物车 ID 中找到订单 ID。这些是我试过的。我无法获得 id_order。我对 Db 查询充满希望。但我认为它不起作用。
您可以使用此代码获取它:$id_order = Order::getOrderByCartId($id_cart);
只要没有注册的订单,就无法获得"id_order"。
如果订单已注册,您确定没有更好的办法,您可以使用以下代码查找已订购的最新购物车:
$this->context->customer->getLastCart(true);
这是导致在验证订单后删除 cookie 的问题。所以它没有显示 id_cart。所以我是这样想的。
$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);