繁体   English   中英

从购物车ID模块prestashop 1.6获取订单ID

[英]Get order id from cart id module prestashop 1.6

控制器/前/ 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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM