简体   繁体   English

如何在 Prestashop 中更改购物车中的产品名称?

[英]How to change product name in the cart in Prestashop?

I want to change the names of some products in the cart.我想更改购物车中某些产品的名称。 I was able to change the price of some products in the cart.我能够更改购物车中某些产品的价格。 But i can't change the names of some products in the cart.但是我无法更改购物车中某些产品的名称。

How can i do that?我怎样才能做到这一点? Is it possible.是否可以。 Thanks for helps.感谢您的帮助。

For your better understanding, below is some of the result from cart->getProducts() action.为了您更好地理解,下面是 cart->getProducts() 操作的一些结果。

在此处输入图像描述

The name of the products, as long as they are in the cart, is read from the product object, so you will have to override the cart->getProducts() method if you want to change their names dynamically.产品的名称,只要它们在购物车中,就会从产品 object 中读取,因此如果您想动态更改它们的名称,则必须覆盖cart->getProducts()方法。

But keep in mind that once a cart becomes an order, product name is copied / stored inside the orderDetail object, where you can freely intervene by renaming the "product_name" field once you know the original id_cart / id_order .但请记住,一旦购物车成为订单,产品名称就会被复制/存储在orderDetail object 中,您可以在知道原始id_cart / id_order后通过重命名“product_name”字段来自由干预。

I solved the problem with the code below.我用下面的代码解决了这个问题。 If you encounter this problem, you can edit the code below for yourself.如果你遇到这个问题,你可以自己编辑下面的代码。 And you must do these actions after validateOrder function or validated the order.并且您必须在 validateOrder function 或验证订单后执行这些操作。

        $order = Order::getByCartId($cart->id);

        $order_details = OrderDetail::getList($order->id);


        foreach ($order_details as $order_detail) {
            if ($order_detail['product_name'] === 'Installment' && (string)$order_detail['product_price'] == (string)$installment_fee) {
                $order_detail_id = $order_detail['id_order_detail'];
            }
        }

        if (!is_null($order_detail_id)) {
            $order_detail = new OrderDetail($order_detail_id);
            $order_detail->product_name = 'Changed product name';
            $order_detail->save();
        }

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

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