The gift in the cart is not displayed correctly in prestashop 1.7.8 and is not displayed correctly in the checkout
Come back
32

The gift in the cart is not displayed correctly in prestashop 1.7.8 and is not displayed correctly in the checkout

I will describe a little about the gift in prestashop

If you are new to prestashop, then you may not know that in the store you can create gifts according to certain rules for a user or for all users, and you can also set a rule for the categories in which the goods are located, configure for which product the gift will be applied - this is all customizable in the discount section, exactly where you create coupons.

To see a gift for a product, simply add the product to the basket and go to the basket, and there you will see a gift.

But I had to meet such an incomprehensible problem with the display of a gift on the cart page. The fact that the gift looks like a product, but not like a gift.

Below I have described the problem and how it can be solved.

Now we will decide

The site sets up a gift for the user according to certain rules in the section "Discounts". And when you create a discount as a coupon, only it does not have a code, then this coupon is like a gift in Figure 1.

Specify an empty code in the discount

(Picture 1. Specify an empty code in the discount)

Specify an empty code in the discount Figure
Specify an empty code in the discount Figure

The gift on the site is displayed in the basket in Figure 2

The gift on the site is displayed in the basket

(Figure 2. What a gift in a basket looks like in 1.7.8 version of prestashop)

A bug was found with the display of this gift in the basket in prestashop 1.7.8 version. The problem is that the gift is displayed as a product in the list, and not as a gift in Figure 3

Problem is that the gift is displayed as a product in the list, and not as a gift

(Figure 3. What should not be displayed for a gift in the basket)

To fix this problem, you need to add a small piece of code in the code, in the file \classes\Cart.php after 858 lines of code, in the function getProducts:

Figure 4 is a good example in the editor

How I edited in the editor

(Figure 4. How I edited in the editor)

That is, in the file \classes\Cart.php it will look like this:

After adding a piece of code to the file, your product page should already display the product as a gift in Figure 5

How the gift should look in the basket

(Figure 5. How the gift should look in the basket)

Outcome

We managed to correctly display the gift in the basket. Further in the code from the array came the key is_gift which stored the wrong value as false and we fixed this problem.

created:
14.09.2022
updated:
15.11.2022
author:
admin
Tags
yandex metrika