Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Help Addon Buy X Get X Free Product Rate Topic   - - - - -

 
  • teosu
  • Senior Member
  • Members
  • Join Date: 09-Oct 14
  • 506 posts

Posted 24 January 2018 - 08:18 AM #1

hi i am developing an addon. when customers buy an product it will give free similar main product amount.

 

i dont want use promotions coz. its not promotion its routine procedure also promotions doesnt calculate amount.

 

anyway i build admin side product tabs, db and select one free product

 

used pre_add_to_cart hook

 

code

foreach ($free_products as $fp) {


                if (fn_check_free_promotion($fp['product_id']) == 'Y') {
                    if (!isset($cart['products'][$p_id])) {

                        $cart['products'][$p_id]['product_id'] = $fp['product_id'];
                        $cart['products'][$p_id]['product_code'] = fn_get_product_code($fp['product_id']);
                        $cart['products'][$p_id]['product'] = fn_get_product_name($fp['product_id']);
                        $cart['products'][$p_id]['main_pair'] = fn_get_cart_product_icon($fp['product_id']);
                        $cart['products'][$p_id]['amount'] = $data['amount'];
                        $cart['products'][$p_id]['stored_price'] = 'Y';
                        $cart['products'][$p_id]['price'] = 0;
                        $cart['change_cart_products'] = true;


                    } else {
                            $_initial_amount = empty($cart['products'][$p_id]['original_amount']) ? $cart['products'][$p_id]['amount'] : $cart['products'][$p_id]['original_amount'];
                            $cart['products'][$p_id]['amount'] = fn_check_amount_in_stock($fp['product_id'], (($update == false) ? 0 : $_initial_amount) + $data['amount'], $data['product_options'] = null, $p_id, (!empty($data['is_edp']) && $data['is_edp'] == 'Y' ? 'Y' : 'N'), 0, $cart, $update == true ? $p_id : 0);
                    }

                }


            }

its work when adding product adding free producs. also second adding updating amount.

also delete with delete_cart_product hook

 

problem is:

when re calculate cart. free products getting site price.

also how can i disable if free product in cart disable adding ?

and how can i disable free product qty changer ?

how can i fix this ?

 

thank you bosses



 
  • galtinbaeva
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 06-Dec 13
  • 3334 posts

Posted 26 January 2018 - 06:40 AM #2

Hello!

 

 

 

when re calculate cart. free products getting site price.

 

Check the "update" mode in the app/controllers/frontend/checkout.php file.

 

 

 

also how can i disable if free product in cart disable adding ?

 

This is not completely clear for me.

 

 

 

and how can i disable free product qty changer ?

 

If you mean cart page, you need this file: design/themes/responsive/templates/views/checkout/components/cart_items.tpl. You should have some parameter that determines free product, so check for it and disable the qty field.


Simtech Development | sales@simtechdev.com | www.simtechdev.com
CERTIFIED CS-CART PARTNER | LICENSES | DEVELOPMENT | ADD-ONS | DESIGN | UPGRADE

Google Analytics Enhanced Ecommerce - get advanced ecommerce analytics


 
  • teosu
  • Senior Member
  • Members
  • Join Date: 09-Oct 14
  • 506 posts

Posted 26 January 2018 - 01:34 PM #3

also how can i disable if free product in cart disable adding ?

 

i want mean if free products in the cart it will disable adding standalone adding.



 
  • al-bert
  • Advanced Member
  • Trial users
  • Join Date: 27-Jul 18
  • 50 posts

Posted 30 May 2019 - 04:55 PM #4

Good luck on the mod, it's about time someone came up with a "buy x get x free" addon.