简体   繁体   English

Prestashop可以访问自定义模块中的购物车变量

[英]Prestashop get access to cart variables in the custom module

In prestashop I want to get the exact payment details step data in my payment module. 在prestashop中,我想在我的付款模块中获取确切的付款明细步骤数据。 So I just made copy the code from order-payment.tpl and used that in my payment execution smarty file. 因此,我只复制了order-payment.tpl中的代码,并将其用于我的付款执行智能文件中。 It showed couple of errors. 它显示了几个错误。 So I just go through the codes and get those values from the cart and made it assign from my payment controller to the smarty template. 因此,我只需遍历代码并从购物车中获取这些值,然后将其从我的付款控制器分配到smarty模板即可。 Everything works fine but still I am getting one error named as 一切正常,但仍然出现一个错误,名为

Undefined index: gift_products .

When I checked the code in Cart.php I got it like this 当我检查Cart.php中的代码时,我得到了这样的代码

$gift_products = array();
$gift_product = $product;
$gift_product['cart_quantity'] = 1;
$gift_product['price'] = 0;
$gift_product['price_wt'] = 0;
$gift_product['total_wt'] = 0;
$gift_product['total'] = 0;
$gift_product['gift'] = true;
$gift_products[] = $gift_product;

I tried to assign the value of gift_products to the smarty like this

public function initContent()
{
    parent::initContent();

    $cart = $this->context->cart;
    $this->context->smarty->assign(array(
        'gift_products' => $cart->gift_products,
    ));

    $this->setTemplate('payment_execution.tpl');
}

But its not working at all. 但是它根本不起作用。 Can someone tell me how to use the variable/array of cart in my module? 有人可以告诉我如何在模块中使用购物车的变量/数组吗? Any help and suggestions will be really appreciable. 任何帮助和建议都是非常可取的。 Thanks. 谢谢。

Use 采用

$summary = $this->context->cart->getSummaryDetails();
$gift_products = $summary['gift_products'];

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

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