♥kymation Posted April 8, 2009 Author Share Posted April 8, 2009 I didn't think it was possible. Did you set the limit to 1? Regards Jim Quote See my profile for a list of my addons and ways to get support. Link to comment Share on other sites More sharing options...
Guest Posted April 10, 2009 Share Posted April 10, 2009 I have set "Maximum Free Products: " to 10... Quote Link to comment Share on other sites More sharing options...
steve_s Posted April 10, 2009 Share Posted April 10, 2009 (edited) Thanks Jim, I shall do some hunting was hoping there might be a simple way to get rid of error, rest assured when i've found out i shall post solution here for others Steve Hi Again Jim, Im almost there with integrating Profit margin and Get 1 Free, no sql errors now, but is putting product_cost in order_products table as 0, Not sure if i am calling the Get 1 free product id correctly, code below would appreciate if you could take a quick look, product_cost is in products table Bold is lines ive added // Get 1 free // If this product qualifies for free product(s) add the free products if (is_array ($free_product = $cart->get1free ($products_id))) { // Update products_ordered (for bestsellers list) // comment out the next line if you don't want free products in the bestseller list tep_db_query("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $free_product['quantity']) . " where products_id = '" . tep_get_prid($free_product['id']) . "'"); $product_cost_query = tep_db_query("select products_cost from " . TABLE_PRODUCTS . " where products_id ='". tep_get_prid($free_product['id']). "'"); $product_cost = tep_db_fetch_array($product_cost_query); $sql_data_array = array('orders_id' => $insert_id, 'products_id' => $free_product['id'], 'products_model' => $free_product['model'], 'products_name' => $free_product['name'], 'products_price' => 0, 'products_cost' => $product_cost['products_cost'], 'final_price' => 0, 'products_tax' => '', 'products_quantity' => $free_product['quantity'] ); tep_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array); $total_weight += ($free_product['quantity'] * $free_product['weight']); } // end Get 1 free Thanks Steve Edited April 10, 2009 by steve_s Quote Link to comment Share on other sites More sharing options...
♥kymation Posted April 10, 2009 Author Share Posted April 10, 2009 The tep_get_prid() function is unnecessary, since you already have the products ID. Try: $product_cost_query = tep_db_query("select products_cost from " . TABLE_PRODUCTS . " where products_id ='". (int) $free_product['id'] . "'"; $product_cost = tep_db_fetch_array($product_cost_query); That may be a bug in the current code. Regards Jim Quote See my profile for a list of my addons and ways to get support. Link to comment Share on other sites More sharing options...
Guest Posted April 10, 2009 Share Posted April 10, 2009 Hello, I have installed your contribution and there is any bug: when I set: Quantity to Qualify: 2 Quantity of Free Product: 4 (I set it to this product: http://www.fitpro.sk/product_info.php?products_id=352) When I put 2 products into cart, it gives me only 1 free product (instead of 4). Could anybody help me, please ? Thanks a million! :) FINALLY I FOUND THAT BUG! And It was not my error in installation!!! in the file catalog/includes/classes/shopping_cart.php at the end of this file - in the function function get1free ($products_id) there was a line with this code: $free_quantity = floor ($products_quantity / $get_1_free['products_qualify_quantity']); I changed it to: $free_quantity = floor ($products_quantity / $get_1_free['products_qualify_quantity']) * $get_1_free['products_free_quantity']; BECAUSE: when I set: Quantity to Qualify: 2 X Quantity of Free Product: 4 (Product B) Maximum Free Items: 100 (Product A) A=2 B would be 4... old code: floor(A/X) is floor(2/2) is 1 NEW CODE: floor(A/X)*B is floor(2/2)*4 is 4 Quote Link to comment Share on other sites More sharing options...
♥kymation Posted April 10, 2009 Author Share Posted April 10, 2009 That's Line 470 in the current release. Your code is unnecessary, since the quantity of free items per product is calculated in Line 489: 'quantity' => $free_quantity * $get_1_free['products_free_quantity'], Your change will duplicate the quantity multiplication. It also interferes with the maximum calculation in Lines 471-473. Regards Jim Quote See my profile for a list of my addons and ways to get support. Link to comment Share on other sites More sharing options...
steve_s Posted April 10, 2009 Share Posted April 10, 2009 The tep_get_prid() function is unnecessary, since you already have the products ID. Try: $product_cost_query = tep_db_query("select products_cost from " . TABLE_PRODUCTS . " where products_id ='". (int) $free_product['id'] . "'"; $product_cost = tep_db_fetch_array($product_cost_query); That may be a bug in the current code. Regards Jim Hi Jim, Thanks i'm still getting zero for some reason think i might have to leave as that for now, at least no errors on order at checkout Steve Quote Link to comment Share on other sites More sharing options...
♥kymation Posted April 11, 2009 Author Share Posted April 11, 2009 Add print $free_product['id']; at that point to see if the variable is being set. If not, track it back to the database query that should have set it. Regards Jim Quote See my profile for a list of my addons and ways to get support. Link to comment Share on other sites More sharing options...
steve_s Posted April 11, 2009 Share Posted April 11, 2009 (edited) Add print $free_product['id']; at that point to see if the variable is being set. If not, track it back to the database query that should have set it. Regards Jim Yep i had to ammend the query slightly tested on phpmyadmin got 0 rows back so added products_id, but doesnt seem to recognise $free_product_id $product_cost_query = tep_db_query("select products_id, products_cost from " . TABLE_PRODUCTS . " where products_id ='". (int)$free_product['id']. "'"); $product_cost = tep_db_fetch_array($product_cost_query); such a smiple thing bieng made hard :rolleyes: I even tried $cart->get1free ($products_id) in sql query Thanks for all the help you gave Jim much appreciated Edited April 11, 2009 by steve_s Quote Link to comment Share on other sites More sharing options...
Guest Posted April 11, 2009 Share Posted April 11, 2009 That's Line 470 in the current release. Your code is unnecessary, since the quantity of free items per product is calculated in Line 489: 'quantity' => $free_quantity * $get_1_free['products_free_quantity'], Your change will duplicate the quantity multiplication. It also interferes with the maximum calculation in Lines 471-473. Regards Jim .... hm, I have downloaded Version 1.4.2... there is line 489 like this: 'quantity' => $free_quantity, If we multiply 'quantity' => $free_quantity * $get_1_free['products_free_quantity'], than we can get more than maximum allowed free items per one shopping cart.... Quote Link to comment Share on other sites More sharing options...
♥kymation Posted April 11, 2009 Author Share Posted April 11, 2009 Apparently I'm not up to date on the latest changes. Sorry about the misunderstanding. You code will work, but it changes the meaning of the maximum free products limit. That's also a valid meaning; just not the one I had intended. Oh well. Regards Jim Quote See my profile for a list of my addons and ways to get support. Link to comment Share on other sites More sharing options...
ssnb Posted April 16, 2009 Share Posted April 16, 2009 (edited) Hay kymation and all the dudes using this contribution. I would like to display the Buy 1 Get 1 free in a box in column right. I use STS Does anyone have anything that would work? Or any idea where I could copy the code from? It would be great if the box did not display if there is no current offer. Thank you. PS even a simple quick dirty hack which would enable to display the item on the index.php main page would be fine ! Just want some way to display it without having to update it manually. Edited April 16, 2009 by ssnb Quote Link to comment Share on other sites More sharing options...
steve_s Posted April 16, 2009 Share Posted April 16, 2009 (edited) Hay kymation and all the dudes using this contribution. I would like to display the Buy 1 Get 1 free in a box in column right. I use STS Does anyone have anything that would work? Or any idea where I could copy the code from? It would be great if the box did not display if there is no current offer. Thank you. PS even a simple quick dirty hack which would enable to display the item on the index.php main page would be fine ! Just want some way to display it without having to update it manually. create a new infobox in includes/boxes/get_1_free.php say now create a template for get_1_free.php you will also need to add this in the includes/modules/sts_inc/sts_column_left.php in your new box paste the following code <?php /* $Id: get_1_free.php 1739 2007-12-20 00:52:16Z hpdl $ Copyright (c) 2003 osCommerce, http://www.oscommerce.com Released under the GNU General Public License */ //random if more than one free product $get_1_free_query = tep_db_query("select products_id from " . TABLE_GET_1_FREE . " order by rand() limit 0,12"); if (tep_db_num_rows($get_1_free_query) > 0) { $free_product = tep_db_fetch_array($get_1_free_query); $product_info_query = tep_db_query("select p.products_id, pd.products_name, p.products_image, pd.products_url, p.products_price, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$free_product['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'"); $product = tep_db_fetch_array($product_info_query); ?> <!-- get_1_free //--> <tr> <td> <?php $info_box_contents = array(); $info_box_contents[] = array('text' => 'Get 1 Free'); new infoBoxHeading($info_box_contents, false, false); $info_box_contents = array(); $info_box_contents[] = array('align' => 'center', 'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $product["products_id"]) . '">' . tep_image(DIR_WS_IMAGES . $product['products_image'], $product['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $product['products_id']) . '">' . $random_product['products_name'] . '</a><br><s>' . $currencies->display_price($product['products_price'], tep_get_tax_rate($product['products_tax_class_id'])); new infoBox($info_box_contents); ?> </td> </tr> <!-- get_1_free_eof //--> <?php } ?> I havent been able to test it but it should work ok Edited April 16, 2009 by steve_s Quote Link to comment Share on other sites More sharing options...
steve_s Posted April 19, 2009 Share Posted April 19, 2009 Hi all I've added margin report http://addons.oscommerce.com/info/1594 i to get this to work with get 1 free find in catalog/includes/classes/shopping_cart.php 'price' => 0, add after it 'cost' => $products['products_cost'], find in catalog/checkout_process.php 'products_price' => 0, add after it 'products_cost' => $free_products['cost'], finaly figured out how to get it to work :) Quote Link to comment Share on other sites More sharing options...
ssnb Posted April 20, 2009 Share Posted April 20, 2009 create a new infobox in includes/boxes/get_1_free.php say now create a template for get_1_free.php you will also need to add this in the includes/modules/sts_inc/sts_column_left.phpin your new box paste the following code I havent been able to test it but it should work ok Thanks - I appreciate your time. Before I go ahead and do a half baked attempt, could you please explain what the STS template might hold? Some sample code would be awesome? Fairly new to STS. When you say need to add this to column_left, do you mean the STS template code, or a link to it? Thanks again SSNB Quote Link to comment Share on other sites More sharing options...
steve_s Posted April 20, 2009 Share Posted April 20, 2009 Thanks - I appreciate your time. Before I go ahead and do a half baked attempt, could you please explain what the STS template might hold? Some sample code would be awesome? Fairly new to STS. When you say need to add this to column_left, do you mean the STS template code, or a link to it? Thanks again SSNB Hi a sample would be like this <table border="0" width="100%" cellspacing="0" cellpadding="0"> <tr> <td> </td> </tr> </table> <table border="0" width="100%" cellspacing="0" cellpadding="0"> <tr> <td><table border="0" width="100%" cellspacing="0" cellpadding="0"> <tr> <td>$content</td> </tr> </table> </td> </tr> </table> </td></tr> in catalog/includes/modules/sts_inc/sts_column_left.php add before the ?> require(DIR_WS_BOXES . 'get_1_free.php'); $sts->restart_capture ('get1free', 'box'); // Get 1 free box now to call that box simply place $get1free in any files you have in your template folder ohh btw change this code if you dont want 12 products in your get 1 free box $get_1_free_query = tep_db_query("select products_id from " . TABLE_GET_1_FREE . " order by rand() limit 0,12"); simply change 12 to what ever number you need Quote Link to comment Share on other sites More sharing options...
rania Posted April 27, 2009 Share Posted April 27, 2009 Hi, i ve tried to download get_1_free_1.4_1 contrib twice and i couldnt find catalog/admin/includes/functions/get_1_free.php .. did i missd something? Quote Link to comment Share on other sites More sharing options...
steve_s Posted April 27, 2009 Share Posted April 27, 2009 Hi i just downloaded Version 1.4.2 this is the full package or BUG FIX: wrong free product count in the includesclasses/shopping_cart.php also a full pakage Hi, i ve tried to download get_1_free_1.4_1 contrib twice and i couldnt find catalog/admin/includes/functions/get_1_free.php ..did i missd something? Quote Link to comment Share on other sites More sharing options...
steve_s Posted April 27, 2009 Share Posted April 27, 2009 Hi i think that is referring to includes/functions/get_1_free.php as there is no such file in admin like that Hi, i ve tried to download get_1_free_1.4_1 contrib twice and i couldnt find catalog/admin/includes/functions/get_1_free.php ..did i missd something? Quote Link to comment Share on other sites More sharing options...
rania Posted April 28, 2009 Share Posted April 28, 2009 Hi i think that is referring to includes/functions/get_1_free.php as there is no such file in admin like that meaning replace this part catalog/admin/includes/functions/get_1_free.php wth this part? includes/classes/shopping_cart.php Quote Link to comment Share on other sites More sharing options...
steve_s Posted April 28, 2009 Share Posted April 28, 2009 (edited) meaning replace this part catalog/admin/includes/functions/get_1_free.php wth this part? includes/classes/shopping_cart.php Hi just knock of admin so its catalog/includes/functions/get_1_free.php or just move to next instruction if you have file in that location includes/classes/shopping_cart.php will be in catalog side Edited April 28, 2009 by steve_s Quote Link to comment Share on other sites More sharing options...
rania Posted April 28, 2009 Share Posted April 28, 2009 Hi just knock of admin so its catalog/includes/functions/get_1_free.php or just move to next instruction if you have file in that location includes/classes/shopping_cart.php will be in catalog side thanks! Quote Link to comment Share on other sites More sharing options...
neonProto Posted May 3, 2009 Share Posted May 3, 2009 Hello, I have been reading through this whole topic history and I am having the same request as many people already had. I am talking about the "apply free product to the whole category, not only one product". I see many people have already asked for this and they haven't found any solution. I am really very much interested if anyone has done it? I am pretty sure, someone already hired programmer to do this. What about making it as a new contribution? Or do you know about other contribution that could be easier to modify to get this "get 1 free for whole category" result? Or kymation, could you please provide quick instructions of what would be needed to change in the code, when someone would like to go this way? I don't mean exact code changes.. but in general, what would be the biggest issues and what to look for when doing these changes into the code.. just to describe very quickly in your words, what to look for? Thank you very much all for any tips. Quote Link to comment Share on other sites More sharing options...
♥kymation Posted May 3, 2009 Author Share Posted May 3, 2009 This can be done, but it will take a lot of changes, and a lot of work to do them all. Database: change the products_id field in the get_1_free table to categories_id. Catalog side: Change all cases where Get 1 Free refers to the products_id to categories_id. This is primarily in catalog/includes/classes/shopping_cart.php, but there will need to be minor changes in most other files as well. The categories_id can be calculated from the products_id if needed, although this can fail when a product is in multiple categories. Admin side: Change the list of products in get_1_free.php to categories, plus change all cases of products_id to categories_id. This is off the top of my head, so I may have missed some details. Not that there are any details in this post anyway. Regards Jim Quote See my profile for a list of my addons and ways to get support. Link to comment Share on other sites More sharing options...
neonProto Posted May 3, 2009 Share Posted May 3, 2009 kymation: thank you very much, i really appreciate your help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.