function convert_product_attributes_result($attributes_values, $load_option_name = true, $can_operate = false) { if ($load_option_name) { $attributes_values->fields['products_options_name'] = zen_options_name($attributes_values->fields['options_id']); $attributes_values->fields['products_options_values_name'] = zen_values_name($attributes_values->fields['options_values_id']); } $attributes_values->fields['products_display_price'] = $attributes_values->fields['price_prefix'] . $attributes_values->fields['options_values_price']; $attributes_values->fields['products_attributes_display_weight'] = $attributes_values->fields['products_attributes_weight_prefix'] . $attributes_values->fields['products_attributes_weight']; require_once DIR_WS_CLASSES . 'currencies.php'; $currencies = new currencies(); $attributes_price_final = zen_get_attributes_price_final($attributes_values->fields["products_attributes_id"], 1, $attributes_values, 'false'); $attributes_price_final_value = $attributes_price_final; $attributes_price_final = $currencies->display_price($attributes_price_final, zen_get_tax_rate(1), 1); $attributes_price_final_onetime = zen_get_attributes_price_final_onetime($attributes_values->fields["products_attributes_id"], 1, $attributes_values); $attributes_price_final_onetime = $currencies->display_price($attributes_price_final_onetime, zen_get_tax_rate(1), 1); $new_attributes_price = ''; if ($attributes_values->fields["attributes_discounted"]) { $new_attributes_price = zen_get_attributes_price_final($attributes_values->fields["products_attributes_id"], 1, '', 'false'); $new_attributes_price = zen_get_discount_calc($attributes_values->fields['products_id'], true, $new_attributes_price); if ($new_attributes_price != $attributes_price_final_value) { $new_attributes_price = '|' . $currencies->display_price($new_attributes_price, zen_get_tax_rate(1), 1); } else { $new_attributes_price = ''; } } $attributes_values->fields['attributes_display_price_final'] = $attributes_price_final . $new_attributes_price . ' ' . $attributes_price_final_onetime; // status $attributes_values->fields['products_status'] = ""; foreach ($this->statuses as $type => $icon_info) { $attributes_values->fields['products_status'] .= self::make_status_link($attributes_values->fields, $type, $icon_info['color'], $icon_info['alt'], $can_operate); } return $attributes_values->fields; }
/** * Test one time price. */ public function testValueOneTimePrice() { foreach ($this->get('productService')->getAllProducts(false, 1) as $product) { foreach ($product->getAttributes() as $attribute) { foreach ($attribute->getValues() as $value) { $er = error_reporting(0); $zprice = zen_get_attributes_price_final_onetime($value->getAttributeValueDetailsId(), 1, ''); error_reporting($er); $this->assertEquals($zprice, $value->getOneTimePrice(false), '%s productId=' . $product->getId() . ' $valueId=' . $value->getAttributeValueId()); } } } }
<tr> <td colspan="10"><?php echo zen_black_line(); ?> </td> </tr> <tr> <?php } else { // attributes display listing // calculate current total attribute price // $attributes_values $attributes_price_final = zen_get_attributes_price_final($attributes_values->fields["products_attributes_id"], 1, $attributes_values, 'false'); $attributes_price_final_value = $attributes_price_final; $attributes_price_final = $currencies->display_price($attributes_price_final, zen_get_tax_rate($product_check->fields['products_tax_class_id']), 1); $attributes_price_final_onetime = zen_get_attributes_price_final_onetime($attributes_values->fields["products_attributes_id"], 1, $attributes_values); $attributes_price_final_onetime = $currencies->display_price($attributes_price_final_onetime, zen_get_tax_rate($product_check->fields['products_tax_class_id']), 1); ?> <td class="smallText"> <?php echo $attributes_values->fields["products_attributes_id"]; ?> </td> <td class="smallText"> <?php // echo $products_name_only; ?> </td> <td class="smallText"> <?php echo $options_name; ?> </td> <td class="smallText"> <?php
function zen_get_attributes_price_final($attribute, $qty = 1, $pre_selected, $include_onetime = 'false') { global $db; global $cart; if ($pre_selected == '' or $attribute != $pre_selected->fields["products_attributes_id"]) { $pre_selected = $db->Execute("select pa.* from " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_attributes_id= '" . $attribute . "'"); } else { // use existing select } // normal attributes price if ($pre_selected->fields["price_prefix"] == '-') { $attributes_price_final -= $pre_selected->fields["options_values_price"]; } else { $attributes_price_final += $pre_selected->fields["options_values_price"]; } // qty discounts $attributes_price_final += zen_get_attributes_qty_prices_onetime($pre_selected->fields["attributes_qty_prices"], $qty); // price factor $display_normal_price = zen_get_products_actual_price($pre_selected->fields["products_id"]); $display_special_price = zen_get_products_special_price($pre_selected->fields["products_id"]); $attributes_price_final += zen_get_attributes_price_factor($display_normal_price, $display_special_price, $pre_selected->fields["attributes_price_factor"], $pre_selected->fields["attributes_price_factor_offset"]); // per word and letter charges if (zen_get_attributes_type($attribute) == PRODUCTS_OPTIONS_TYPE_TEXT) { // calc per word or per letter } // onetime charges if ($include_onetime == 'true') { $pre_selected_onetime = $pre_selected; $attributes_price_final += zen_get_attributes_price_final_onetime($pre_selected->fields["products_attributes_id"], 1, $pre_selected_onetime); } return $attributes_price_final; }
if ($products_options->fields['attributes_discounted'] == 1) { // apply product discount to attributes if discount is on // $new_attributes_price = $products_options->fields['options_values_price']; $new_attributes_price = zen_get_attributes_price_final($products_options->fields["products_attributes_id"], 1, '', 'false'); $new_attributes_price = zen_get_discount_calc((int) $_GET['products_id'], true, $new_attributes_price); } else { // discount is off do not apply $new_attributes_price = $products_options->fields['options_values_price']; } // reverse negative values for display if ($new_attributes_price < 0) { $new_attributes_price = -$new_attributes_price; } if ($products_options->fields['attributes_price_onetime'] != 0 or $products_options->fields['attributes_price_factor_onetime'] != 0) { $show_onetime_charges_description = 'true'; $new_onetime_charges = zen_get_attributes_price_final_onetime($products_options->fields["products_attributes_id"], 1, ''); $price_onetime = TEXT_ONETIME_CHARGE_SYMBOL . $currencies->display_price($new_onetime_charges, zen_get_tax_rate($product_info->fields['products_tax_class_id'])); } else { $price_onetime = ''; } if ($products_options->fields['attributes_qty_prices'] != '' or $products_options->fields['attributes_qty_prices_onetime'] != '') { $show_attributes_qty_prices_description = 'true'; $show_attributes_qty_prices_icon = 'true'; } if ($products_options->fields['options_values_price'] != '0' and ($products_options->fields['product_attribute_is_free'] != '1' and $product_info->fields['product_is_free'] != '1')) { // show sale maker discount if a percentage $products_options_display_price = ATTRIBUTES_PRICE_DELIMITER_PREFIX . $products_options->fields['price_prefix'] . $currencies->display_price($new_attributes_price, zen_get_tax_rate($product_info->fields['products_tax_class_id'])) . ATTRIBUTES_PRICE_DELIMITER_SUFFIX; } else { // if product_is_free and product_attribute_is_free if ($products_options->fields['product_attribute_is_free'] == '1' and $product_info->fields['product_is_free'] == '1') { $products_options_display_price = TEXT_ATTRIBUTES_PRICE_WAS . $products_options->fields['price_prefix'] . $currencies->display_price($new_attributes_price, zen_get_tax_rate($product_info->fields['products_tax_class_id'])) . TEXT_ATTRIBUTE_IS_FREE;
function zen_get_attributes_price_final($attribute, $qty = 1, $pre_selected, $include_onetime = 'false') { global $db; $attributes_price_final = 0; if ($pre_selected == '' or $attribute != $pre_selected->fields["products_attributes_id"]) { $pre_selected = $db->Execute("select pa.* from " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_attributes_id= '" . (int) $attribute . "'"); } else { // use existing select } // normal attributes price // Dual Pricing start if ($_SESSION['customer_whole']) { if ($_SESSION['customer_whole'] != '0') { $i = (int) $_SESSION['customer_whole']; $i--; $option_price_array = $pre_selected->fields['options_values_price_w']; $optionprice = explode(",", $option_price_array); $options_values_price = (double) $optionprice[$i]; if ($options_values_price == '0' || $options_values_price == '') { $options_values_price = (double) $optionprice[0]; } $the_base_price += $options_values_price; if ($options_values_price == '0') { $options_values_price = $pre_selected->fields['options_values_price']; } } else { $options_values_price = $pre_selected->fields['options_values_price']; } } else { $options_values_price = $pre_selected->fields['options_values_price']; } if ($pre_selected->fields["price_prefix"] == '-') { $attributes_price_final -= $pre_selected->fields["options_values_price"]; } else { $attributes_price_final += $pre_selected->fields["options_values_price"]; // Dual Pricing end } // qty discounts $attributes_price_final += zen_get_attributes_qty_prices_onetime($pre_selected->fields["attributes_qty_prices"], $qty); // price factor $display_normal_price = zen_get_products_actual_price($pre_selected->fields["products_id"]); $display_special_price = zen_get_products_special_price($pre_selected->fields["products_id"]); $attributes_price_final += zen_get_attributes_price_factor($display_normal_price, $display_special_price, $pre_selected->fields["attributes_price_factor"], $pre_selected->fields["attributes_price_factor_offset"]); // per word and letter charges if (zen_get_attributes_type($attribute) == PRODUCTS_OPTIONS_TYPE_TEXT) { // calc per word or per letter } // onetime charges if ($include_onetime == 'true') { $pre_selected_onetime = $pre_selected; $attributes_price_final += zen_get_attributes_price_final_onetime($pre_selected->fields["products_attributes_id"], 1, $pre_selected_onetime); } return $attributes_price_final; }