Search code examples
phpprestashope-commerce

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.

enter image description here


Solution

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