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 attribute price. */ public function testValuePrice() { foreach ($this->get('productService')->getAllProducts(false, 1) as $product) { foreach ($product->getAttributes() as $attribute) { foreach ($attribute->getValues() as $value) { if ($value->isDiscounted()) { $er = error_reporting(0); $zprice = zen_get_attributes_price_final($value->getAttributeValueDetailsId(), 1, ''); $zprice = zen_get_discount_calc($product->getId(), true, $zprice); error_reporting($er); } else { $zprice = $value->getValuePrice(); } // default is 4 decimal digits... $this->assertEquals((int) (10000 * $zprice), (int) (10000 * $value->getPrice(false)), '%s productId=' . $product->getId() . ' $valueId=' . $value->getAttributeValueId() . '/' . $value->getAttributeValueDetailsId()); } } } }
/** * Method to calculate one time price of attributes for a given item * * @param mixed the product ID of the item to check * @param decimal item quantity * @return decimal the pice of the items attributes * @global object access to the db object */ function attributes_price_onetime_charges($products_id, $qty) { global $db; $attributes_price_onetime = 0; if (isset($this->contents[$products_id]['attributes'])) { reset($this->contents[$products_id]['attributes']); while (list($option, $value) = each($this->contents[$products_id]['attributes'])) { $attribute_price_query = "select *\n from " . TABLE_PRODUCTS_ATTRIBUTES . "\n where products_id = '" . (int) $products_id . "'\n and options_id = '" . (int) $option . "'\n and options_values_id = '" . (int) $value . "'"; $attribute_price = $db->Execute($attribute_price_query); // Dual Pricing start if ($_SESSION['customer_id']) { $customers_id = $_SESSION['customer_id']; $customer_check = $db->Execute("select * from " . TABLE_CUSTOMERS . " where customers_id = '{$customers_id}'"); if ($customer_check->fields['customers_whole'] != "0") { $i = $customer_check->fields['customers_whole']; $i--; $options_value_price = (double) $attribute_price->fields['options_values_price_w']; } else { $options_value_price = $attribute_price->fields['options_values_price']; } } else { $options_value_price = $attribute_price->fields['options_values_price']; } // Dual Pricing end $new_attributes_price = 0; $discount_type_id = ''; $sale_maker_discount = ''; // if ($attribute_price->fields['product_attribute_is_free']) { if ($attribute_price->fields['product_attribute_is_free'] == '1' and zen_get_products_price_is_free((int) $products_id)) { // no charge } else { $discount_type_id = ''; $sale_maker_discount = ''; $new_attributes_price = zen_get_discount_calc($products_id, $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price'], $qty); ////////////////////////////////////////////////// // calculate additional one time charges //// one time charges // attributes_price_onetime if ($attribute_price->fields['attributes_price_onetime'] > 0) { if ((int) $products_id != $products_id) { die('I DO NOT MATCH ' . $products_id); } $attributes_price_onetime += $attribute_price->fields['attributes_price_onetime']; } // attributes_price_factor_onetime $added_charge = 0; if ($attribute_price->fields['attributes_price_factor_onetime'] > 0) { $chk_price = zen_get_products_base_price($products_id); $chk_special = zen_get_products_special_price($products_id, false); $added_charge = zen_get_attributes_price_factor($chk_price, $chk_special, $attribute_price->fields['attributes_price_factor_onetime'], $attribute_price->fields['attributes_price_factor_onetime_offset']); $attributes_price_onetime += $added_charge; } // attributes_qty_prices_onetime $added_charge = 0; if ($attribute_price->fields['attributes_qty_prices_onetime'] != '') { $chk_price = zen_get_products_base_price($products_id); $chk_special = zen_get_products_special_price($products_id, false); $added_charge = zen_get_attributes_qty_prices_onetime($attribute_price->fields['attributes_qty_prices_onetime'], $qty); $attributes_price_onetime += $added_charge; } ////////////////////////////////////////////////// } } } return $attributes_price_onetime; }
echo ($attributes_values->fields["attributes_price_base_included"] == '0' ? '<a href="' . zen_href_link(FILENAME_ATTRIBUTES_CONTROLLER, 'action=set_flag_attributes_price_base_included' . '&attributes_id=' . $attributes_values->fields["products_attributes_id"] . (isset($_GET['option_page']) ? '&option_page=' . $_GET['option_page'] . '&' : '') . (isset($_GET['value_page']) ? '&value_page=' . $_GET['value_page'] . '&' : '') . (isset($_GET['attribute_page']) ? '&attribute_page=' . $_GET['attribute_page'] : '') . '&products_filter=' . $products_filter . '¤t_category_id=' . $current_category_id) . '" onClick="divertClick(this.href);return false;">' . zen_image(DIR_WS_IMAGES . 'icon_purple_off.gif', LEGEND_ATTRIBUTE_PRICE_BASE_INCLUDED) . '</a>' : '<a href="' . zen_href_link(FILENAME_ATTRIBUTES_CONTROLLER, 'action=set_flag_attributes_price_base_included' . '&attributes_id=' . $attributes_values->fields["products_attributes_id"] . (isset($_GET['option_page']) ? '&option_page=' . $_GET['option_page'] . '&' : '') . (isset($_GET['value_page']) ? '&value_page=' . $_GET['value_page'] . '&' : '') . (isset($_GET['attribute_page']) ? '&attribute_page=' . $_GET['attribute_page'] : '') . '&products_filter=' . $products_filter . '¤t_category_id=' . $current_category_id) . '" onClick="divertClick(this.href);return false;">' . zen_image(DIR_WS_IMAGES . 'icon_purple_on.gif', LEGEND_ATTRIBUTE_PRICE_BASE_INCLUDED)) . '</a>'; ?> </td> <td class="smallText" align="center"><?php echo ($attributes_values->fields["attributes_required"] == '0' ? '<a href="' . zen_href_link(FILENAME_ATTRIBUTES_CONTROLLER, 'action=set_flag_attributes_required' . '&attributes_id=' . $attributes_values->fields["products_attributes_id"] . (isset($_GET['option_page']) ? '&option_page=' . $_GET['option_page'] . '&' : '') . (isset($_GET['value_page']) ? '&value_page=' . $_GET['value_page'] . '&' : '') . (isset($_GET['attribute_page']) ? '&attribute_page=' . $_GET['attribute_page'] : '') . '&products_filter=' . $products_filter . '¤t_category_id=' . $current_category_id) . '" onClick="divertClick(this.href);return false;">' . zen_image(DIR_WS_IMAGES . 'icon_red_off.gif', LEGEND_ATTRIBUTES_REQUIRED) . '</a>' : '<a href="' . zen_href_link(FILENAME_ATTRIBUTES_CONTROLLER, 'action=set_flag_attributes_required' . '&attributes_id=' . $attributes_values->fields["products_attributes_id"] . (isset($_GET['option_page']) ? '&option_page=' . $_GET['option_page'] . '&' : '') . (isset($_GET['value_page']) ? '&value_page=' . $_GET['value_page'] . '&' : '') . (isset($_GET['attribute_page']) ? '&attribute_page=' . $_GET['attribute_page'] : '') . '&products_filter=' . $products_filter . '¤t_category_id=' . $current_category_id) . '" onClick="divertClick(this.href);return false;">' . zen_image(DIR_WS_IMAGES . 'icon_red_on.gif', LEGEND_ATTRIBUTES_REQUIRED)) . '</a>'; ?> </td> </tr> </table> </td> <?php } $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($products_filter, 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($product_check->fields['products_tax_class_id']), 1); } else { $new_attributes_price = ''; } } ?> <td align="right" class="smallText"><?php echo $attributes_price_final . $new_attributes_price . ' ' . $attributes_price_final_onetime; ?> </td> <?php if ($action != '') { ?> <td width='120' align="center" class="smallText"> </td>
$products_options_display_price = ''; $new_attributes_price = ''; $price_onetime = ''; $products_options_array[] = array('id' => $products_options->fields['products_options_values_id'], 'text' => $products_options->fields['products_options_values_name']); if (CUSTOMERS_APPROVAL == '2' and $_SESSION['customer_id'] == '' or STORE_STATUS == '1' or (CUSTOMERS_APPROVAL_AUTHORIZATION == '1' or CUSTOMERS_APPROVAL_AUTHORIZATION == '2') and $_SESSION['customers_authorization'] == '' or CUSTOMERS_APPROVAL == '2' and $_SESSION['customers_authorization'] == '2' or CUSTOMERS_APPROVAL_AUTHORIZATION == '2' and $_SESSION['customers_authorization'] != 0) { $new_attributes_price = ''; $new_options_values_price = 0; $products_options_display_price = ''; $price_onetime = ''; } else { // collect price information if it exists 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 = ''; }
$attributestypenumber[$i] = $row8a[0]; } } $result8c = mysql_query("SELECT products_options_name FROM " . TABLE_PRODUCTS_OPTIONS . " WHERE products_options_id='{$attributestypenumber[$i]}'") or die('Failed to connect database: 8'); while ($row8c = mysql_fetch_array($result8c, MYSQL_NUM)) { $attributestype[$i] = $row8c[0]; } $result9d = mysql_query("SELECT products_price, product_is_free FROM " . TABLE_PRODUCTS . " WHERE products_id='{$add_product_products_id}'") or die('Failed to connect database:9d'); while ($row9d = mysql_fetch_array($result9d, MYSQL_NUM)) { $prodpricebase = $row9d[0]; $prodisfree = $row9d[1]; } $result10a = mysql_query("SELECT options_values_price, price_prefix, attributes_discounted, products_attributes_id, attributes_price_onetime, attributes_price_factor_onetime, attributes_price_factor_onetime_offset, attributes_price_factor, attributes_price_factor_offset, attributes_qty_prices, attributes_qty_prices_onetime, attributes_price_letters, attributes_price_letters_free, attributes_price_words, attributes_price_words_free, product_attribute_is_free FROM " . TABLE_PRODUCTS_ATTRIBUTES . " WHERE options_values_id='{$_POST[$sendoptionon]}' AND products_id='{$add_product_products_id}'") or die("Failed to connect database: "); while ($row10a = mysql_fetch_array($result10a, MYSQL_NUM)) { if ($row10a[2] == 1 && $_POST[applyspecialstoprice]) { $newpricechange = zen_get_discount_calc($add_product_products_id, $row10a[3], $row10a[0], $add_product_quantity); } else { $newpricechange = $row10a[0]; } $addtotheprice[$i] = $row10a[0]; $addorsubfromprice[$i] = $row10a[1]; if ($row10a[15] == 0 || $prodisfree == 0) { if ($row10a[1] == "-") { $AddedOptionsPrice -= $newpricechange; } else { $AddedOptionsPrice += $newpricechange; } if (ATTRIBUTES_ENABLED_PRICE_FACTOR == true) { if ($row10a[7] != 0) { $AddedOptionsPrice += $row10a[7] * $prodpricebase; }
/** * Method to calculate one time price of attributes for a given item * * @param mixed the product ID of the item to check * @param decimal item quantity * @return decimal the pice of the items attributes */ public function attributes_price_onetime_charges($products_id, $qty) { $attributes_price_onetime = 0; if (isset($this->contents[$products_id]['attributes'])) { reset($this->contents[$products_id]['attributes']); while (list($option, $value) = each($this->contents[$products_id]['attributes'])) { $attribute_price_query = "select *\n from %table.products_attributes%\n where products_id = '" . (int) $products_id . "'\n and options_id = '" . (int) $option . "'\n and options_values_id = '" . (int) $value . "'"; $attribute_price = $this->getDb()->Execute($attribute_price_query); $new_attributes_price = 0; $discount_type_id = ''; $sale_maker_discount = ''; if ($attribute_price->fields['product_attribute_is_free'] == '1' and zen_get_products_price_is_free((int) $products_id)) { // no charge } else { $discount_type_id = ''; $sale_maker_discount = ''; $new_attributes_price = zen_get_discount_calc($products_id, $attribute_price->fields['products_attributes_id'], $attribute_price->fields['options_values_price'], $qty); ////////////////////////////////////////////////// // calculate additional one time charges //// one time charges // attributes_price_onetime if ($attribute_price->fields['attributes_price_onetime'] > 0) { if ((int) $products_id != $products_id) { die('I DO NOT MATCH ' . $products_id); } $attributes_price_onetime += $attribute_price->fields['attributes_price_onetime']; } // attributes_price_factor_onetime $added_charge = 0; if ($attribute_price->fields['attributes_price_factor_onetime'] > 0) { $chk_price = zen_get_products_base_price($products_id); $chk_special = zen_get_products_special_price($products_id, false); $added_charge = zen_get_attributes_price_factor($chk_price, $chk_special, $attribute_price->fields['attributes_price_factor_onetime'], $attribute_price->fields['attributes_price_factor_onetime_offset']); $attributes_price_onetime += $added_charge; } // attributes_qty_prices_onetime $added_charge = 0; if ($attribute_price->fields['attributes_qty_prices_onetime'] != '') { $chk_price = zen_get_products_base_price($products_id); $chk_special = zen_get_products_special_price($products_id, false); $added_charge = zen_get_attributes_qty_prices_onetime($attribute_price->fields['attributes_qty_prices_onetime'], $qty); $attributes_price_onetime += $added_charge; } } } } return $attributes_price_onetime; }
echo $breadcrumb->trail(BREAD_CRUMBS_SEPARATOR); ?> </td> </tr> <tr> <td colspan="2" class="smallText"> <?php if (false) { echo 'Looking at ' . (int) $_GET['products_id'] . '<br />'; echo 'Base Price ' . zen_get_products_base_price((int) $_GET['products_id']) . '<br />'; echo 'Actual Price ' . zen_get_products_actual_price((int) $_GET['products_id']) . '<br />'; echo 'Special Price ' . zen_get_products_special_price((int) $_GET['products_id'], true) . '<br />'; echo 'Sale Maker Discount Type ' . zen_get_products_sale_discount_type((int) $_GET['products_id']) . '<br />'; echo 'Discount Calc ' . zen_get_discount_calc((int) $_GET['products_id']) . '<br />'; echo 'Discount Calc Attr $100 $75 $50 $25 ' . zen_get_discount_calc((int) $_GET['products_id'], true, 100) . ' | ' . zen_get_discount_calc((int) $_GET['products_id'], true, 75) . ' | ' . zen_get_discount_calc((int) $_GET['products_id'], true, 50) . ' | ' . zen_get_discount_calc((int) $_GET['products_id'], true, 25) . '<br />'; } ?> </td> </tr> <?php if (PRODUCT_INFO_PREVIOUS_NEXT == '1' or PRODUCT_INFO_PREVIOUS_NEXT == '3') { ?> <tr> <td colspan="2" align="center"> <?php require $template->get_template_dir('/tpl_products_next_previous.php', DIR_WS_TEMPLATE, $current_page_base, 'templates') . '/tpl_products_next_previous.php'; ?> </td> </tr>
function eo_get_product_attribute_prices($attr_id, $attr_value = '', $qty = 1) { global $db; $retval = array('onetime_charges' => 0, 'price' => 0); $attribute_price = $db->Execute('SELECT * ' . 'FROM `' . TABLE_PRODUCTS_ATTRIBUTES . '` ' . 'WHERE `products_attributes_id`=\'' . (int) $attr_id . '\''); $attr_id = (int) $attr_id; $qty = (int) $qty; $product_id = (int) $attribute_price->fields['products_id']; // Only check when attributes is not free or the product is not free if ($attribute_price->fields['product_attribute_is_free'] != '1' || !zen_get_products_price_is_free($product_id)) { // Handle based upon discount enabled if ($attribute_price->fields['attributes_discounted'] == '1') { // Calculate proper discount for attributes $added_charge = zen_get_discount_calc($product_id, $attr_id, $attribute_price->fields['options_values_price'], $qty); } else { $added_charge = $attribute_price->fields['options_values_price']; } // Handle negative price prefix // Other price prefixes ("+" and "") should add so no special processing if ($attribute_price->fields['price_prefix'] == '-') { $added_charge = -1 * $added_charge; } $retval['price'] += $added_charge; ////////////////////////////////////////////////// // calculate additional charges // products_options_value_text if (zen_get_attributes_type($attr_id) == PRODUCTS_OPTIONS_TYPE_TEXT) { $text_words = zen_get_word_count_price($attr_value, $attribute_price->fields['attributes_price_words_free'], $attribute_price->fields['attributes_price_words']); $text_letters = zen_get_letters_count_price($attr_value, $attribute_price->fields['attributes_price_letters_free'], $attribute_price->fields['attributes_price_letters']); $retval['price'] += $text_letters; $retval['price'] += $text_words; } // attributes_price_factor $added_charge = 0; if ($attribute_price->fields['attributes_price_factor'] > 0) { $chk_price = zen_get_products_base_price($products_id); $chk_special = zen_get_products_special_price($products_id, false); $added_charge = zen_get_attributes_price_factor($chk_price, $chk_special, $attribute_price->fields['attributes_price_factor'], $attribute_price->fields['attributes_price_factor_offset']); $retval['price'] += $added_charge; } // attributes_qty_prices $added_charge = 0; if ($attribute_price->fields['attributes_qty_prices'] != '') { $chk_price = zen_get_products_base_price($products_id); $chk_special = zen_get_products_special_price($products_id, false); $added_charge = zen_get_attributes_qty_prices_onetime($attribute_price->fields['attributes_qty_prices'], $qty); $retval['price'] += $added_charge; } // attributes_price_onetime if ($attribute_price->fields['attributes_price_onetime'] > 0) { $retval['onetime_charges'] = (double) $attribute_price->fields['attributes_price_onetime']; } // attributes_price_factor_onetime $added_charge = 0; if ($attribute_price->fields['attributes_price_factor_onetime'] > 0) { $chk_price = zen_get_products_base_price($products_id); $chk_special = zen_get_products_special_price($products_id, false); $added_charge = zen_get_attributes_price_factor($chk_price, $chk_special, $attribute_price->fields['attributes_price_factor_onetime'], $attribute_price->fields['attributes_price_factor_onetime_offset']); $retval['onetime_charges'] += $added_charge; } // attributes_qty_prices_onetime $added_charge = 0; if ($attribute_price->fields['attributes_qty_prices_onetime'] != '') { $chk_price = zen_get_products_base_price($products_id); $chk_special = zen_get_products_special_price($products_id, false); $added_charge = zen_get_attributes_qty_prices_onetime($attribute_price->fields['attributes_qty_prices_onetime'], $qty); $retval['onetime_charges'] += $added_charge; } //////////////////////////////////////////////// } return $retval; }