Jump to content

Gift product per quantity


nikpony

Recommended Posts

Hello to all,

i need your urgent help.

I have already create a cart rule, so where a customer add a product in cart it also add a free product as a gift.

But i want, as customer increase the quantity of products that he want, also the gift to increase.

So in a real example i need when a customer has in cart 2 pieces of an Iphone, to get also 2 pieces of a charger which is the gift and not 1 as Prestashop core do.

 

I am trying to modify it in Cart.php class file but i am spending hours and i can't sleep many days now in order to fix it.

 

Any help or suggestion would be very helpful but please be as quick as you can, because we are on a hurry.

 

Thanks in advance and i am waiting your suggestions.

Link to comment
Share on other sites

Thank you shokinro for your reply...i am trying to solve it with this method but my knowledge don't help me to do it...i am writing here the part of this method in cart.php that adding a quantity in the cart for gift products...

 

If somebody could help me i would be very grateful....

if ((int)$cartRule->gift_product)
			$this->updateQty(1, $cartRule->gift_product, $cartRule->gift_product_attribute, false, 'up', 0, null, false);

		return true;
	}
Link to comment
Share on other sites

I think the piece of code you listed is from addCartRule() method, this is executed when you add cart rule. and it is executed one time only.

1. Instead of 2 for the first parameter, for you will need to check the quantity of related product and use the correct quantity.

 

$this->updateQty(1,

 

2. As I mentioned you need add additional code in updateQty() so that when the related product quantity is changed, you will also need to update the gift product quantity too,

Link to comment
Share on other sites

You can use $this->getProducts() to get all products in the shipping cart,

and then find out the product that is related to your gift product, and find out the quantity of that product and then update the gift product quantity.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...