简体   繁体   中英

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.

在此处输入图像描述

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.

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 .

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.

        $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();
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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