Post by KoalaBear » Sun Dec 24, 2017 7:15 am

Hello,

I am trying to create a custom modification and will really need some help.

So, I want specific products from my store to come with specific gift. What I am trying to do:

1. Set if the product have a gift or not.
2. Create custom product (the gift) which will not be visible in the store and will have price 0.
3. When the user adds the product with gift, the gift will automatically be added alongside the product to cart.

As for the first point - I've added the functionality to my admin panel. I've added checkbox which is writing in custom field called free_gift in my oc_product table, so I have 2 options - free_gift = 1 if the product have a gift and free_gift = 0 if it doesn't.

I have created the specific gift and hid it from the store.

But I can not figure it out how to add it automatically to cart. So far I am trying to edit system/library/cart.php, but with no luck.

Any help will be much appreciated, because... well, I am not a programmer and everything is like a puzzle for me :)

OC 2.0.3.1

Have a nice Christmas!

Newbie

Posts

Joined
Mon Apr 24, 2017 10:04 pm

Post by KoalaBear » Sun Dec 24, 2017 4:57 pm

Slept, woked up and figured it out.

If anyone needs solution - catalog/controller/checkout/cart.php

if (!$json) { (line 346), add:

if ($product_info['free_gift'] == 1) {
$this->cart->add($this->request->post['product_id'], $quantity, $option, $recurring_id);
$this->cart->add(THE_ID_OF_GIFT_PRODUCT, 1, $option, $recurring_id);
} else {
$this->cart->add($this->request->post['product_id'], $quantity, $option, $recurring_id);
}

Not the best sollution, but working :)

Newbie

Posts

Joined
Mon Apr 24, 2017 10:04 pm

Post by straightlight » Sun Dec 24, 2017 11:33 pm

Take note that Opencart also allows to copy products over other categories. Using the suggestion above does not make category validations when considering a gift product.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 19 guests