I can't believe that some form of solution has been found. It seems like it was simple to correct and I can't believe that no one has done this before.. Okay, there may be some "tests" or improvements still to be made around the code to protect the user, but... Sum and total, this is the correction(s) that were needed to go from start to finish on processing a product that is or is not priced by attributes where the attributes can be associated with the special OR a sale (OR combination)... I need someone to confirm/disprove aspects of it, but it became all too clear...
Anyways, still need the CONSTANT to support transferring the individual attribute related prices over to the checkout_ related path so:
includes/classes/shopping_cart.php needs to include the below highlighted item which seems to "fix" the issue of at least attributes + price factor + special price coming out to be the incorrect total at checkout.
Code:
function attributes_price($products_id) {
global $db, $currencies;
$total_attributes_price = 0;
$qty = $this->contents[$products_id]['qty'];
if (isset($this->contents[$products_id]['attributes'])) {
if (!defined('ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL')) define('ATTRIBUTES_PRICE_FACTOR_FROM_SPECIAL', 1); // mc12345678 Added to apply the attribute's price factor and price factor offset against the provided special price if a special is present otherwise against the provided price when returning the value from the function zen_get_attributes_price_factor found in includes/functions/functions_prices.php
reset($this->contents[$products_id]['attributes']);
while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
$attributes_price = 0;
Then working from the end of the file up (so line numbers hold true throughout) in includes/functions/functions_prices.php:
Find line 1083:
Code:
$attributes_price_final += $pre_selected->fields["options_values_price"];
and replace with:
Code:
// $attributes_price_final += $pre_selected->fields["options_values_price"];
$attributes_price_final += zen_get_discount_calc($pre_selected->fields["products_id"], $pre_selected->fields["products_attributes_id"], $pre_selected->fields["options_values_price"] + (zen_get_products_price_is_priced_by_attributes($pre_selected->fields["products_id"]) ? zen_products_lookup($pre_selected->fields["products_id"], 'products_price') : 0));
Then find line 1081:
Code:
$attributes_price_final -= $pre_selected->fields["options_values_price"];
and replace with:
Code:
// $attributes_price_final -= $pre_selected->fields["options_values_price"];
$attributes_price_final -= zen_get_discount_calc($pre_selected->fields["products_id"], $pre_selected->fields["products_attributes_id"], (zen_get_products_price_is_priced_by_attributes($pre_selected->fields["products_id"]) ? zen_products_lookup($pre_selected->fields["products_id"], 'products_price') : 0) + (zen_get_products_price_is_priced_by_attributes($pre_selected->fields["products_id"]) ? -1 : 1) * $pre_selected->fields["options_values_price"]);
Line 560:
Code:
$calc = ($attributes_amount * $special_price_discount);
replace with:
Code:
$calc = ($attributes_amount * $sale_price_discount);
Line 539:
Code:
if ($special_price_discount != 0) {
$calc = ($attributes_amount * $special_price_discount);
replace with:
Code:
if ($sale_price_discount != 0) {
$calc = ($attributes_amount * $sale_price_discount);
At line 501 add/insert the following:
Code:
if ($new_products_price != 0) {
$sale_price_discount = ($new_sale_price != 0 ? ($new_sale_price/$new_products_price) : 1);
} else {
$sale_price_discount = '';
}
And in includes/modules/YOUR_TEMPLATE/attributes.php (or rather the base install), comment out line 126:
Code:
// $new_attributes_price = zen_get_discount_calc((int)$_GET['products_id'], true, $new_attributes_price);
And then are some similar changes that can be made to the admin side. I was working on changing the information presented in the admin attributes_controller such that the discount calculated would be displayed, but I've set that aside for the moment...
Committed these changes to a ZC PR
Bookmarks