uncommonhound Posted November 22, 2011 Share Posted November 22, 2011 I've searched through all the add-ons and read the forums for the past few hours (and many times before). With all the generous contributions for osCommerce.. is there really no add-on that will apply specials correctly to products with attributes? ..meaning a percentage discount on the total attribute price, and not just the base price prior to the additional attribute price. Thanks so much to anyone that can point me in the right direction! Quote Link to comment Share on other sites More sharing options...
uncommonhound Posted November 22, 2011 Author Share Posted November 22, 2011 Does anyone even want to have a discussion about this? Isn't it a feature that many people need? Quote Link to comment Share on other sites More sharing options...
hookswitch Posted March 15, 2012 Share Posted March 15, 2012 I need this, too. If I come up with a solution I'll post it. Quote Link to comment Share on other sites More sharing options...
Guest Posted March 15, 2012 Share Posted March 15, 2012 @@hookswitch I don't believe there is currently a way to put an attribute on sale. Chris Quote Link to comment Share on other sites More sharing options...
hookswitch Posted March 15, 2012 Share Posted March 15, 2012 I got this figured out for osCommerce 2.3.1. To apply the specials_percent discount to any product which has a specials_percent entry in the specials table, I modified calculate_price() in includes/classes/currencies.php: function calculate_price($products_price, $products_tax, $quantity = 1, $product_id = '') { global $currency; if($product_id){ // Apply specials_percent discount $discount = get_specials_discount_percent($product_id); if($discount > 0){ // Don't apply if specials_percent is zero (as in the case of products with a static discount amount $products_price = $products_price * $discount; } } return tep_round(tep_add_tax($products_price, $products_tax), $this->currencies[$currency]['decimal_places']) * $quantity; } And also add the argument to display_price(): function display_price($products_price, $products_tax, $quantity = 1, $product_id = '') { return $this->format($this->calculate_price($products_price, $products_tax, $quantity, $product_id)); } After that, you need the new function get_specials_discount_percent(). In includes/functions/general.php: //// // Return the specials_percent for a given product so we can apply it to attributes option values // TABLES: specials function get_specials_discount_percent($product_id){ $product_query = tep_db_query("select specials_percent from " . TABLE_SPECIALS . " where products_id = '" . (int)$product_id . "' and status = 1"); $product = tep_db_fetch_array($product_query); return $product['specials_percent']; } NOW, 2 things need to happen: Add the product_id as the 4th argument wherever display_price() or calculate_price() are called. Modify product_info.php to display the discounted price in the options list. #1: In includes/classes/shopping_cart.php (in 2 spots): $this->total -= $currencies->calculate_price($attribute_price['options_values_price'], $products_tax, $qty, (int)$prid); In shopping_cart.php (different file): echo ' <td valign="top">' . $products_name . '</td>' . ' <td align="right" valign="top"><strong>' . $currencies->display_price($products[$i]['final_price'], tep_get_tax_rate($products[$i]['tax_class_id']), $products[$i]['quantity'], $products[$i]['id']) . '</strong></td>' . ' </tr>'; In checkout_process.php: //------insert customer choosen option eof ---- $products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . ' (' . $order->products[$i]['model'] . ') = ' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty'], $order->products[$i]['id']) . $products_ordered_attributes . "\n"; In checkout_confirmation.php: echo ' <td align="right" valign="top">' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty'], $order->products[$i]['id']) . '</td>' . "\n" . ' </tr>' . "\n"; and in includes/classes/order.php: $shown_price = $currencies->calculate_price($this->products[$index]['final_price'], $this->products[$index]['tax'], $this->products[$index]['qty'], $products[$i]['id']); #2: In product_info.php: // Apply specials_percent discount to attributes option values $discount = get_specials_discount_percent((int)$HTTP_GET_VARS['products_id']); $products_options['options_values_price'] = $products_options['options_values_price'] * $discount; I hope I didn't forget anything. No time to make a contribution out of it right now, but maybe someone else would like to do that, or osCommerce devs might consider somehow making this a toggle-able option in the admin under Specials. Good luck. Quote Link to comment Share on other sites More sharing options...
hookswitch Posted March 19, 2012 Share Posted March 19, 2012 (edited) I DID forget something. Or rather, didn't notice. Line item prices shown in admin/orders.php and admin/invoice.php also need some help displaying the price minus discount (though with my above changes the Subtotal and Totals are summed correctly with tax applied). Anyway, it needs to be applied in the class, but first we need the previously-used function get_specials_discount_percent() from general.php to be present in admin/includes/general.php (there are slightly different "includes" under admin/ in case you didn't notice): In admin/includes/functions/general.php: //// // Return the specials_percent for a given product so we can apply it to attributes option values - CB 03-19-2012 // TABLES: specials function get_specials_discount_percent($product_id){ $product_query = tep_db_query("select specials_percent from " . TABLE_SPECIALS . " where products_id = '" . (int)$product_id . "' and status = 1"); $product = tep_db_fetch_array($product_query); return $product['specials_percent']; } //// // Return the price with the specials discount applied function apply_specials_discount($product_id, $price){ $discount = get_specials_discount_percent($product_id); if($discount &--#62; 0){ $price = $price * $discount; } return $price; } In admin/includes/classes/order.php, wherever you see a "price" being displayed, wrap that value in our function call (you have to pass the product_id too, of course, so that it can look up the specials discount percent): while ($orders_products = tep_db_fetch_array($orders_products_query)) { $this-&--#62;products[$index] = array('qty' =&--#62; $orders_products['products_quantity'], 'name' =&--#62; $orders_products['products_name'], 'model' =&--#62; $orders_products['products_model'], 'tax' =&--#62; $orders_products['products_tax'], 'price' =&--#62; apply_specials_discount($orders_products['products_id'],$orders_products['products_price']), 'final_price' =&--#62; apply_specials_discount($orders_products['products_id'],$orders_products['final_price'])); $subindex = 0; $attributes_query = tep_db_query("select products_options, products_options_values, options_values_price, price_prefix from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int)$order_id . "' and orders_products_id = '" . (int)$orders_products['orders_products_id'] . "'"); if (tep_db_num_rows($attributes_query)) { while ($attributes = tep_db_fetch_array($attributes_query)) { $this-&--#62;products[$index]['attributes'][$subindex] = array('option' =&--#62; $attributes['products_options'], 'value' =&--#62; $attributes['products_options_values'], 'prefix' =&--#62; $attributes['price_prefix'], 'price' =&--#62; apply_specials_discount($orders_products['products_id'],$attributes['options_values_price'])); $subindex++; } } $index++; } OK, done. NOTE: This seems odd: the final_price in the database for each item of the order is displayed as the product price without the discount applied. We applied it in the shopping cart calculation, however, so the customer was charged appropriately and the totals reflect the amount charged. If this becomes a problem, and it becomes necessary to make sure that final_price is inserted as the price less the discount, I'll post about it. So far, so good, however. Edited March 19, 2012 by hookswitch Quote Link to comment Share on other sites More sharing options...
limar Posted September 5, 2012 Share Posted September 5, 2012 Isn't this possible with the master/slave products contribution? Quote Link to comment Share on other sites More sharing options...
modem2.0 Posted September 16, 2012 Share Posted September 16, 2012 NOTE: This seems odd: the final_price in the database for each item of the order is displayed as the product price without the discount applied. We applied it in the shopping cart calculation, however, so the customer was charged appropriately and the totals reflect the amount charged. If this becomes a problem, and it becomes necessary to make sure that final_price is inserted as the price less the discount, I'll post about it. So far, so good, however. Hi hookswitch, is there a way to fix this? Thanks! 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.