function _calcAddPoint() { global $db, $order; require_once DIR_FS_CATALOG . $GLOBALS['point_base']->dir . 'classes/class.point.php'; $point =& new point($_SESSION['customer_id']); $this->amount = 0; $this->point = 0; if (MODULE_POINT_PRODUCTSRATE_STATUS == 'true') { foreach ($order->products as $fields) { $products_id = zen_get_prid($fields['id']); $products_pointrate = $GLOBALS['point_productsrate']->getPointRate($products_id); if ($products_pointrate !== false) { $this->point += (int) ($fields['final_price'] * $fields['qty'] * $products_pointrate / 100); } else { $this->amount += $fields['final_price'] * $fields['qty']; } } } else { foreach ($order->products as $fields) { $this->amount += $fields['final_price'] * $fields['qty']; } } if (MODULE_POINT_GROUPRATE_STATUS == 'true') { $query = "\r\n select\r\n customers_group_pricing\r\n from\r\n " . TABLE_CUSTOMERS . "\r\n where\r\n customers_id = :customersID\r\n ;"; $query = $db->bindVars($query, ':customersID', $_SESSION['customer_id'], 'integer'); $result = $db->Execute($query); if ($result->RecordCount() > 0) { $group_id = $result->fields['customers_group_pricing']; $group_pointrate = $GLOBALS['point_grouprate']->getPointRate($group_id); if ($group_pointrate !== false) { $this->rate = $group_pointrate; } } } if (MODULE_POINT_CUSTOMERSRATE_STATUS == 'true') { $customers_pointrate = $GLOBALS['point_customersrate']->getPointRate($_SESSION['customer_id']); if ($customers_pointrate !== false) { $this->rate = $customers_pointrate; } } $this->point += (int) ($this->amount * $this->rate / 100); $deduction = 0; if (is_object($GLOBALS['ot_coupon'])) { $deduction += $GLOBALS['ot_coupon']->deduction; } if (is_object($GLOBALS['cot_gv'])) { $deduction += $GLOBALS['cot_gv']->deduction; } if (is_object($GLOBALS['ot_subpoint'])) { $deduction += $GLOBALS['ot_subpoint']->deduction; } if (is_object($GLOBALS['ot_group_pricing'])) { $deduction += $GLOBALS['ot_group_pricing']->deduction; } $this->point -= ceil($deduction * $this->rate / 100); }
function getProductObject($pProductsMixed) { $productsId = zen_get_prid($pProductsMixed); if (BitBase::verifyId($productsId)) { if (!isset($this->mProductObjects[$productsId])) { if ($this->mProductObjects[$productsId] = bc_get_commerce_product($productsId)) { $ret =& $this->mProductObjects[$productsId]; } } } return $this->mProductObjects[$productsId]; }
function pwas_get_products_stock($products_id, $attributes = '') { global $db; $products_id = zen_get_prid($products_id); // get product level stock quantity $stock_query = "select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . (int) $products_id . "'"; // check if there attributes for this product if (is_array($attributes) and sizeof($attributes) > 0) { // check if any attribute stock values have been set for the product // (only of there is will we continue, otherwise we'll use product level data) $attribute_stock = $db->Execute("select stock_id from " . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . " where products_id = '" . (int) $products_id . "'"); if ($attribute_stock->RecordCount() > 0) { // prepare to search for details for the particular attribute combination passed as a parameter if (sizeof($attributes) > 1) { if (isset($attributes[0]['value_id'])) { $ary = array(); for ($i = 0; $i < count($attributes); $i++) { $ary[] = $attributes[$i]['value_id']; } } else { $ary = $attributes; } $first_search = 'where options_values_id in ("' . implode('","', $ary) . '")'; } else { if (isset($attributes[0]['value_id'])) { $first_search = 'where options_values_id="' . $attributes[0]['value_id'] . '"'; } else { foreach ($attributes as $attribute) { $first_search = 'where options_values_id="' . $attribute . '"'; } } } // obtain the attribute ids $query = 'select products_attributes_id from ' . TABLE_PRODUCTS_ATTRIBUTES . ' ' . $first_search . ' and products_id="' . $products_id . '" order by products_attributes_id'; $attributes_new = $db->Execute($query); while (!$attributes_new->EOF) { $stock_attributes[] = $attributes_new->fields['products_attributes_id']; $attributes_new->MoveNext(); } if (sizeof($stock_attributes) > 1) { $stock_attributes = implode(',', $stock_attributes); } else { $stock_attributes = $stock_attributes[0]; } // create the query to find attribute stock $stock_query = 'select quantity as products_quantity from ' . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . ' where products_id = "' . (int) $products_id . '" and stock_attributes="' . $stock_attributes . '"'; } } // get the stock value for the product or attribute combination $stock_values = $db->Execute($stock_query); return $stock_values->fields['products_quantity']; }
function create_add_products($pOrdersId, $zf_mode = false) { global $gBitDb, $gBitUser, $currencies, $order_total_modules, $order_totals; $this->StartTrans(); // initialized for the email confirmation $this->products_ordered_html = ''; // lowstock email report $this->email_low_stock = ''; foreach (array_keys($this->contents) as $productsKey) { // Stock Update - Joao Correia if (STOCK_LIMITED == 'true') { if (DOWNLOAD_ENABLED == 'true') { $stock_query_raw = "SELECT products_quantity, pad.products_attributes_filename\n\t\t\t\t\t\t\t\t\t\tFROM " . TABLE_PRODUCTS . " p\n\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN " . TABLE_PRODUCTS_OPTIONS_MAP . " pom ON(p.`products_id`=pom.`products_id`)\n\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES . " pa ON (pa.`products_options_values_id`=pom.`products_options_values_id`)\n\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad ON(pa.`products_attributes_id`=pad.`products_attributes_id`)\n\t\t\t\t\t\t\t\t\t\tWHERE p.`products_id` = ?"; $bindVars = array(zen_get_prid($this->contents[$productsKey]['id'])); // Will work with only one option for downloadable products // otherwise, we have to build the query dynamically with a loop $products_attributes = $this->contents[$productsKey]['attributes']; if (is_array($products_attributes)) { $stock_query_raw .= " AND pa.`products_options_id` = ? AND pa.`products_options_values_id` = ?"; $bindVars[] = zen_get_options_id($products_attributes[0]['option_id']); $bindVars[] = $products_attributes[0]['value_id']; } $stockValues = $gBitDb->query($stock_query_raw, $bindVars); } else { $stockValues = $gBitDb->getRow("select `products_quantity` from " . TABLE_PRODUCTS . " where `products_id` = ?", array(zen_get_prid($this->contents[$productsKey]['id']))); } if ($stock_values && $stock_values->RecordCount() > 0) { // do not decrement quantities if products_attributes_filename exists if (DOWNLOAD_ENABLED != 'true' || !empty($stockValues['products_attributes_filename'])) { $stock_left = $stockValues['products_quantity'] - $this->contents[$productsKey]['products_quantity']; $this->contents[$productsKey]['stock_reduce'] = $this->contents[$productsKey]['products_quantity']; } else { $stock_left = $stockValues['products_quantity']; } // $this->contents[$productsKey]['stock_value'] = $stockValues['products_quantity']; $gBitDb->Execute("update " . TABLE_PRODUCTS . " set `products_quantity` = '" . $stock_left . "' where `products_id` = '" . zen_get_prid($this->contents[$productsKey]['id']) . "'"); // if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT == 'false') ) { if ($stock_left < 1) { // only set status to off when not displaying sold out if (SHOW_PRODUCTS_SOLD_OUT == '0') { $gBitDb->Execute("update " . TABLE_PRODUCTS . " set `products_status` = '0' where `products_id` = '" . zen_get_prid($this->contents[$productsKey]['id']) . "'"); } } // for low stock email if ($stock_left <= STOCK_REORDER_LEVEL) { // WebMakers.com Added: add to low stock email $this->email_low_stock .= 'ID# ' . zen_get_prid($this->contents[$productsKey]['id']) . "\t\t" . $this->contents[$productsKey]['model'] . "\t\t" . $this->contents[$productsKey]['name'] . "\t\t" . ' Qty Left: ' . $stock_left . "\n"; } } } // Update products_ordered (for bestsellers list) $gBitDb->Execute("update " . TABLE_PRODUCTS . " set `products_ordered` = `products_ordered` + " . sprintf('%f', $this->contents[$productsKey]['products_quantity']) . " where `products_id` = '" . zen_get_prid($this->contents[$productsKey]['id']) . "'"); $sql_data_array = array('orders_id' => $pOrdersId, 'products_id' => zen_get_prid($this->contents[$productsKey]['id']), 'products_model' => $this->contents[$productsKey]['model'], 'products_name' => $this->contents[$productsKey]['name'], 'products_price' => $this->contents[$productsKey]['price'], 'products_cogs' => $this->contents[$productsKey]['products_cogs'], 'products_wholesale' => $this->contents[$productsKey]['products_wholesale'], 'products_commission' => $this->contents[$productsKey]['commission'], 'final_price' => $this->contents[$productsKey]['final_price'], 'onetime_charges' => $this->contents[$productsKey]['onetime_charges'], 'products_tax' => $this->contents[$productsKey]['tax'], 'products_quantity' => $this->contents[$productsKey]['products_quantity'], 'products_priced_by_attribute' => $this->contents[$productsKey]['products_priced_by_attribute'], 'product_is_free' => $this->contents[$productsKey]['product_is_free'], 'products_discount_type' => $this->contents[$productsKey]['products_discount_type'], 'products_discount_type_from' => $this->contents[$productsKey]['products_discount_type_from']); $gBitDb->associateInsert(TABLE_ORDERS_PRODUCTS, $sql_data_array); $this->contents[$productsKey]['orders_products_id'] = zen_db_insert_id(TABLE_ORDERS_PRODUCTS, 'orders_products_id'); $order_total_modules->update_credit_account($productsKey); //ICW ADDED FOR CREDIT CLASS SYSTEM if (!empty($this->contents[$productsKey]['purchase_group_id'])) { $gBitUser->addUserToGroup($gBitUser->mUserId, $this->contents[$productsKey]['purchase_group_id']); } //------insert customer choosen option to order-------- $attributes_exist = '0'; $this->products_ordered_attributes = ''; if (!empty($this->contents[$productsKey]['attributes'])) { $attributes_exist = '1'; foreach (array_keys($this->contents[$productsKey]['attributes']) as $j) { $optionValues = zen_get_option_value((int) $this->contents[$productsKey]['attributes'][$j]['option_id'], (int) $this->contents[$productsKey]['attributes'][$j]['value_id']); if (!empty($optionValues['purchase_group_id'])) { $gBitUser->addUserToGroup($gBitUser->mUserId, $optionValues['purchase_group_id']); } if (!empty($optionValues['products_options_id'])) { //clr 030714 update insert query. changing to use values form $order->contents for products_options_values. $sql_data_array = array('orders_id' => $pOrdersId, 'orders_products_id' => $this->contents[$productsKey]['orders_products_id'], 'products_options' => $optionValues['products_options_name'], 'products_options_values' => $this->contents[$productsKey]['attributes'][$j]['value'], 'options_values_price' => $optionValues['options_values_price'], 'options_values_cogs' => $optionValues['options_values_cogs'], 'options_values_wholesale' => $optionValues['options_values_wholesale'], 'price_prefix' => $optionValues['price_prefix'], 'product_attribute_is_free' => $optionValues['product_attribute_is_free'], 'products_attributes_wt' => $optionValues['products_attributes_wt'], 'products_attributes_wt_pfix' => $optionValues['products_attributes_wt_pfix'], 'attributes_discounted' => (int) $optionValues['attributes_discounted'], 'attributes_price_base_inc' => (int) $optionValues['attributes_price_base_inc'], 'attributes_price_onetime' => $optionValues['attributes_price_onetime'], 'attributes_price_factor' => $optionValues['attributes_price_factor'], 'attributes_pf_offset' => $optionValues['attributes_pf_offset'], 'attributes_pf_onetime' => $optionValues['attributes_pf_onetime'], 'attributes_pf_onetime_offset' => $optionValues['attributes_pf_onetime_offset'], 'attributes_qty_prices' => $optionValues['attributes_qty_prices'], 'attributes_qty_prices_onetime' => $optionValues['attributes_qty_prices_onetime'], 'attributes_price_words' => $optionValues['attributes_price_words'], 'attributes_price_words_free' => $optionValues['attributes_price_words_free'], 'attributes_price_letters' => $optionValues['attributes_price_letters'], 'attributes_price_letters_free' => $optionValues['attributes_price_letters_free'], 'products_options_id' => $optionValues['products_options_id'], 'products_options_values_id' => $optionValues['products_options_values_id']); $gBitDb->associateInsert(TABLE_ORDERS_PRODUCTS_ATTRIBUTES, $sql_data_array); } if (DOWNLOAD_ENABLED == 'true' && isset($optionValues['products_attributes_filename']) && zen_not_null($optionValues['products_attributes_filename'])) { $sql_data_array = array('orders_id' => $pOrdersId, 'orders_products_id' => $this->contents[$productsKey]['orders_products_id'], 'orders_products_filename' => $optionValues['products_attributes_filename'], 'download_maxdays' => $optionValues['products_attributes_maxdays'], 'download_count' => $optionValues['products_attributes_maxcount']); $gBitDb->associateInsert(TABLE_ORDERS_PRODUCTS_DOWNLOAD, $sql_data_array); } $this->products_ordered_attributes .= "\n\t" . $optionValues['products_options_name'] . ' ' . zen_decode_specialchars($this->contents[$productsKey]['attributes'][$j]['value']); } } //------insert customer choosen option eof ---- $this->total_weight += $this->contents[$productsKey]['products_quantity'] * $this->contents[$productsKey]['weight']; // $this->total_tax += zen_calculate_tax($total_products_price, $products_tax) * $this->contents[$productsKey]['products_quantity']; // $this->total_cost += $total_products_price; $this->products_ordered_html .= '<tr>' . '<td class="product-details alignright" valign="top" width="30">' . $this->contents[$productsKey]['products_quantity'] . ' x</td>' . '<td class="product-details" valign="top">' . $this->contents[$productsKey]['name'] . ($this->contents[$productsKey]['model'] != '' ? ' (' . $this->contents[$productsKey]['model'] . ') ' : '') . '<span style="white-space:nowrap;"><small><em> ' . $this->products_ordered_attributes . '</em></small></span></td>' . '<td class="product-details-num alignright" valign="top">' . $currencies->display_price($this->contents[$productsKey]['final_price'], $this->contents[$productsKey]['tax'], $this->contents[$productsKey]['products_quantity']) . ($this->contents[$productsKey]['onetime_charges'] != 0 ? '</td></tr><tr><td class="product-details">' . TEXT_ONETIME_CHARGES_EMAIL . '</td>' . '<td>' . $currencies->display_price($this->contents[$productsKey]['onetime_charges'], $this->contents[$productsKey]['tax'], 1) : '') . '</td></tr>'; } $order_total_modules->apply_credit(); //ICW ADDED FOR CREDIT CLASS SYSTEM $this->CompleteTrans(); }
/** * Method to calculate the number of items in a cart based on an abitrary property * * $check_what is the fieldname example: 'products_is_free' * $check_value is the value being tested for - default is 1 * Syntax: $_SESSION['cart']->in_cart_check('product_is_free','1'); * * @param string product field to check * @param mixed value to check for * @return integer number of items matching restraint */ function in_cart_check($check_what, $check_value = '1') { global $db; // if nothing is in cart return 0 if (!is_array($this->contents)) { return 0; } // compute total quantity for field $in_cart_check_qty = 0; reset($this->contents); while (list($products_id, ) = each($this->contents)) { $testing_id = zen_get_prid($products_id); // check if field it true $product_check = $db->Execute("select " . $check_what . " as check_it from " . TABLE_PRODUCTS . " where products_id='" . $testing_id . "' limit 1"); if ($product_check->fields['check_it'] == $check_value) { $in_cart_check_qty += $this->contents[$products_id]['qty']; } } return $in_cart_check_qty; }
/** * Return a product's stock count. * * @param int The product id of the product who's stock we want */ function zen_get_products_stock($products_id) { global $db; $products_id = zen_get_prid($products_id); $stock_query = "select products_quantity\r\n from " . TABLE_PRODUCTS . "\r\n where products_id = '" . (int) $products_id . "'"; $stock_values = $db->Execute($stock_query); return $stock_values->fields['products_quantity']; }
function zen_get_products_stock($products_id, $attributes = null, $dupTest = null) { global $db; $products_id = zen_get_prid($products_id); // Need to evaluate if product is SBA tracked in case the page is posted without the attributes as a separate check. if ($products_id && (!is_array($attributes) && !zen_not_null($attributes))) { //For products without associated attributes, get product level stock quantity $stock_query = "select products_quantity \n from " . TABLE_PRODUCTS . " \n where products_id = :products_id:"; $stock_query = $db->bindVars($stock_query, ':products_id:', $products_id, 'integer'); $stock_values = $db->Execute($stock_query); return $stock_values->fields['products_quantity']; } elseif (is_array($attributes) && sizeof($attributes) > 0) { //For products with associated attributes, to do the following: // 1. Check if the attribute has been added to the SBA Stock Page. // 2. Check if the attribute(s) are listed in seperate rows or are combined into a single row. // mc12345678 - The following seems like it could be compressed more/do less searches. Now that this seems to work, there is some code that can be compressed. /* mc12345678 Comment about the $attribute_stock test is really to see if the product is tracked by SBA. */ // check if any attribute stock values have been set for the product in the SBA table, if not do the else part if (zen_product_is_sba($products_id)) { // prepare to search for details for the particular attribute combination passed as a parameter $stock_attributes_list = array(); $stock_attributes = ''; $stock_attributes_list = zen_get_sba_attribute_ids($products_id, $attributes, 'products'); if (sizeof($stock_attributes_list) == 1 && !$dupTest) { // echo '<br />Single Attribute <br />'; $stock_attributes = $stock_attributes_list[0]; // create the query to find single attribute stock $stock_query = 'select stock_id, quantity as products_quantity from ' . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . ' where products_id = :products_id: and stock_attributes=:stock_attributes:'; $stock_query = $db->bindVars($stock_query, ':products_id:', $products_id, 'integer'); $stock_query = $db->bindVars($stock_query, ':stock_attributes:', $stock_attributes, 'passthru'); $stock_values = $db->Execute($stock_query); // return the stock qty for the attribute if (!$stock_values->EOF) { return $stock_values->fields['products_quantity']; } else { return false; } } elseif (sizeof($stock_attributes_list) > 1) { // mc12345678 multiple attributes are associated with the product // question is how these relate to the SBA variant. // echo '<br />Multiple attributes <br />'; $stockResult = null; //This part checks for "attribute combinations" in the SBA table. (Multiple attributes per Stock ID Row, Multiple Attribute types in stock_attributes Field i.e, 123,321,234) $TMPstock_attributes = implode(',', $stock_attributes_list); // create the query to find attribute stock $stock_query = 'select stock_id, quantity as products_quantity from ' . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . ' where products_id = :products_id: and stock_attributes like :TMPstock_attributes:'; $stock_query = $db->bindVars($stock_query, ':products_id:', $products_id, 'integer'); $stock_query = $db->bindVars($stock_query, ':TMPstock_attributes:', $TMPstock_attributes, 'string'); // get the stock value for the combination $stock_values = $db->Execute($stock_query); $stockResult = $stock_values->fields['products_quantity']; if ($dupTest) { //return the stock for "attribute combinations" with a flag if ($stockResult > 0) { return 'true'; } return 'false'; } elseif (!$stock_values->EOF && $stock_values->RecordCount() == 1) { //return the stock for "attribute combinations" return $stockResult; } else { //This part is for attributes that are all listed separately in the SBA table for the product $stockResult = null; $returnedStock = null; $i = 0; $notAccounted = false; foreach ($stock_attributes_list as $eachAttribute) { // create the query to find attribute stock //echo '<br />Multiple Attributes selected (one attribute type per product)<br />'; $stock_query = 'select quantity as products_quantity from ' . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . ' where products_id = :products_id: and stock_attributes= :eachAttribute:'; $stock_query = $db->bindVars($stock_query, ':products_id:', $products_id, 'integer'); $stock_query = $db->bindVars($stock_query, ':eachAttribute:', $eachAttribute, 'passthru'); // get the stock value for the combination $stock_values = $db->Execute($stock_query); $stockResult = $stock_values->fields['products_quantity']; if ($stockResult->EOF) { $notAccounted = true; } //special test to account for qty when all attributes are listed seperetly if (!zen_not_null($returnedStock) && $i == 0) { //set initial value if ($stock_values->EOF) { $returnedStock = 0; } else { $returnedStock = $stockResult; } } elseif ($returnedStock > $stockResult) { //update for each attribute, if qty is lower than the previous one $returnedStock = $stockResult; } // end if first stock item of attribute $i++; } // end for each attribute. if ($notAccounted) { return false; } else { return $returnedStock; } } } } else { //Used with products that have attributes But the attribute is not listed in the SBA Stock table. //Get product level stock quantity $stock_query = "select products_quantity from " . TABLE_PRODUCTS . " where products_id = :products_id:"; $stock_query = $db->bindVars($stock_query, ':products_id:', $products_id, 'integer'); $stock_values = $db->Execute($stock_query); return $stock_values->fields['products_quantity']; } } return; }
$messageStack->add_session('checkout_payment', ERROR_NO_PAYMENT_MODULE_SELECTED, 'error'); } if (is_array($payment_modules->modules)) { $payment_modules->pre_confirmation_check(); } if ($messageStack->size('checkout_payment') > 0) { zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL')); } //echo $messageStack->size('checkout_payment'); //die('here'); // Stock Check $flagAnyOutOfStock = false; $stock_check = array(); if (STOCK_CHECK == 'true') { for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) { if ($stock_check[$i] = zen_check_stock($order->products[$i]['id'], $product_in_order[zen_get_prid($order->products[$i]['id'])])) { $flagAnyOutOfStock = true; } } // Out of Stock if (STOCK_ALLOW_CHECKOUT != 'true' && $flagAnyOutOfStock == true) { zen_redirect(zen_href_link(FILENAME_SHOPPING_CART)); } } // update customers_referral with $_SESSION['gv_id'] if ($_SESSION['cc_id']) { $discount_coupon_query = "SELECT coupon_code\r\n FROM " . TABLE_COUPONS . "\r\n WHERE coupon_id = :couponID"; $discount_coupon_query = $db->bindVars($discount_coupon_query, ':couponID', $_SESSION['cc_id'], 'integer'); $discount_coupon = $db->Execute($discount_coupon_query); $customers_referral_query = "SELECT customers_referral\r\n FROM " . TABLE_CUSTOMERS . "\r\n WHERE customers_id = :customersID"; $customers_referral_query = $db->bindVars($customers_referral_query, ':customersID', $_SESSION['customer_id'], 'integer');
function create_add_products($zf_insert_id, $zf_mode = false) { global $db, $currencies, $order_total_modules, $order_totals, $zco_notifier; // initialized for the email confirmation $this->products_ordered = ''; $this->products_ordered_html = ''; $this->subtotal = 0; $this->total_tax = 0; // lowstock email report $this->email_low_stock = ''; for ($i = 0, $n = sizeof($this->products); $i < $n; $i++) { $custom_insertable_text = ''; // Stock Update - Joao Correia if (STOCK_LIMITED == 'true') { if (DOWNLOAD_ENABLED == 'true') { $stock_query_raw = "select p.products_quantity, pad.products_attributes_filename, p.product_is_always_free_shipping\n\n from " . TABLE_PRODUCTS . " p\n\n left join " . TABLE_PRODUCTS_ATTRIBUTES . " pa\n\n on p.products_id=pa.products_id\n\n left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad\n\n on pa.products_attributes_id=pad.products_attributes_id\n\n WHERE p.products_id = '" . zen_get_prid($this->products[$i]['id']) . "'"; // Will work with only one option for downloadable products // otherwise, we have to build the query dynamically with a loop $products_attributes = $this->products[$i]['attributes']; if (is_array($products_attributes)) { $stock_query_raw .= " AND pa.options_id = '" . $products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . $products_attributes[0]['value_id'] . "'"; } $stock_values = $db->Execute($stock_query_raw); } else { $stock_values = $db->Execute("select * from " . TABLE_PRODUCTS . " where products_id = '" . zen_get_prid($this->products[$i]['id']) . "'"); } $zco_notifier->notify('NOTIFY_ORDER_PROCESSING_STOCK_DECREMENT_BEGIN'); if ($stock_values->RecordCount() > 0) { // do not decrement quantities if products_attributes_filename exists if (DOWNLOAD_ENABLED != 'true' || $stock_values->fields['product_is_always_free_shipping'] == 2 || !$stock_values->fields['products_attributes_filename']) { $stock_left = $stock_values->fields['products_quantity'] - $this->products[$i]['qty']; $this->products[$i]['stock_reduce'] = $this->products[$i]['qty']; } else { $stock_left = $stock_values->fields['products_quantity']; } // $this->products[$i]['stock_value'] = $stock_values->fields['products_quantity']; $db->Execute("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . zen_get_prid($this->products[$i]['id']) . "'"); if (defined('TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK')) { // kuroi: Begin Stock by Attributes additions // added to update quantities of products with attributes $attribute_search = array(); $attribute_stock_left = STOCK_REORDER_LEVEL + 1; // kuroi: prevent false low stock triggers if (isset($this->products[$i]['attributes']) and sizeof($this->products[$i]['attributes']) > 0) { foreach ($this->products[$i]['attributes'] as $attributes) { $attribute_search[] = $attributes['value_id']; } if (sizeof($attribute_search) > 1) { $attribute_search = 'where options_values_id in ("' . implode('","', $attribute_search) . '")'; } else { $attribute_search = 'where options_values_id="' . $attribute_search[0] . '"'; } $query = 'select products_attributes_id from ' . TABLE_PRODUCTS_ATTRIBUTES . ' ' . $attribute_search . ' and products_id="' . zen_get_prid($this->products[$i]['id']) . '" order by products_attributes_id'; $attributes = $db->Execute($query); $stock_attributes_search = array(); while (!$attributes->EOF) { $stock_attributes_search[] = $attributes->fields['products_attributes_id']; $attributes->MoveNext(); } if (sizeof($stock_attributes_search) > 1) { $stock_attributes_search = implode(',', $stock_attributes_search); } else { foreach ($stock_attributes_search as $attribute_search) { $stock_attributes_search1 = $attribute_search; } $stock_attributes_search = $stock_attributes_search1; } $get_quantity_query = 'select quantity from ' . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . ' where products_id="' . zen_get_prid($this->products[$i]['id']) . '" and stock_attributes="' . $stock_attributes_search . '"'; $attribute_stock_available = $db->Execute($get_quantity_query); $attribute_stock_left = $attribute_stock_available->fields['quantity'] - $this->products[$i]['qty']; $attribute_update_query = 'update ' . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . ' set quantity=' . $attribute_stock_left . ' where products_id="' . zen_get_prid($this->products[$i]['id']) . '" and stock_attributes="' . $stock_attributes_search . '"'; $db->Execute($attribute_update_query); } // kuroi: End Stock by Attribute additions } if ($stock_left <= 0) { // only set status to off when not displaying sold out if (SHOW_PRODUCTS_SOLD_OUT == '0') { $db->Execute("update " . TABLE_PRODUCTS . " set products_status = 0 where products_id = '" . zen_get_prid($this->products[$i]['id']) . "'"); } } // for low stock email if ($stock_left <= STOCK_REORDER_LEVEL) { // WebMakers.com Added: add to low stock email $this->email_low_stock .= 'ID# ' . zen_get_prid($this->products[$i]['id']) . ', ' . $this->products[$i]['model'] . ', ' . $this->products[$i]['name'] . ', ' . 'Stock: ' . $stock_left . "\n\n"; // kuroi: trigger and details for attribute low stock email } elseif ($attribute_stock_left <= STOCK_REORDER_LEVEL) { $this->email_low_stock .= 'ID# ' . zen_get_prid($this->products[$i]['id']) . ', ' . $this->products[$i]['model'] . ', ' . $this->products[$i]['name'] . ', '; foreach ($this->products[$i]['attributes'] as $attributes) { $this->email_low_stock .= $attributes['option'] . ': ' . $attributes['value'] . ', '; } $this->email_low_stock .= 'Stock: ' . $attribute_stock_left . "\n\n"; } } } // Update products_ordered (for bestsellers list) // $db->Execute("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . zen_get_prid($order->products[$i]['id']) . "'"); $db->Execute("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%f', $this->products[$i]['qty']) . " where products_id = '" . zen_get_prid($this->products[$i]['id']) . "'"); $zco_notifier->notify('NOTIFY_ORDER_PROCESSING_STOCK_DECREMENT_END'); $products_name = $this->products[$i]['name']; if (strlen($products_name) > 64) { $products_name = substr($products_name, 0, 64); } $sql_data_array = array('orders_id' => $zf_insert_id, 'products_id' => zen_get_prid($this->products[$i]['id']), 'products_model' => $this->products[$i]['model'], 'products_name' => $products_name, 'products_price' => $this->products[$i]['price'], 'final_price' => $this->products[$i]['final_price'], 'onetime_charges' => $this->products[$i]['onetime_charges'], 'products_tax' => $this->products[$i]['tax'], 'products_quantity' => $this->products[$i]['qty'], 'products_priced_by_attribute' => $this->products[$i]['products_priced_by_attribute'], 'product_is_free' => $this->products[$i]['product_is_free'], 'products_discount_type' => $this->products[$i]['products_discount_type'], 'products_discount_type_from' => $this->products[$i]['products_discount_type_from'], 'products_prid' => $this->products[$i]['id']); zen_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array); $order_products_id = $db->Insert_ID(); $zco_notifier->notify('NOTIFY_ORDER_DURING_CREATE_ADDED_PRODUCT_LINE_ITEM', array_merge(array('orders_products_id' => $order_products_id), $sql_data_array)); if (FEC_GIFT_WRAPPING_SWITCH == 'true') { // Gift wrap $wrap_count = 0; $wrapsettings = $_SESSION['wrapsettings']; $prid = $this->products[$i]['id']; for ($q = 1; $q <= $this->products[$i]['qty']; $q++) { if (!isset($wrapsettings[$prid][$q]) || $wrapsettings[$prid][$q] == 0) { continue; } $sql_data_array = array('orders_id' => $zf_insert_id, 'orders_products_id' => $order_products_id, 'wrap' => $wrapsettings[$prid][$q]); zen_db_perform(TABLE_ORDERS_GIFTWRAP, $sql_data_array); $wrap_count++; } // End gift wrap } $zco_notifier->notify('NOTIFY_ORDER_PROCESSING_CREDIT_ACCOUNT_UPDATE_BEGIN'); $order_total_modules->update_credit_account($i); //ICW ADDED FOR CREDIT CLASS SYSTEM $zco_notifier->notify('NOTIFY_ORDER_PROCESSING_ATTRIBUTES_BEGIN'); //------ bof: insert customer-chosen options to order-------- $attributes_exist = '0'; $this->products_ordered_attributes = ''; if (isset($this->products[$i]['attributes'])) { $attributes_exist = '1'; for ($j = 0, $n2 = sizeof($this->products[$i]['attributes']); $j < $n2; $j++) { if (DOWNLOAD_ENABLED == 'true') { $attributes_query = "select popt.products_options_name, poval.products_options_values_name,\n\n pa.options_values_price, pa.price_prefix,\n\n pa.product_attribute_is_free, pa.products_attributes_weight, pa.products_attributes_weight_prefix,\n\n pa.attributes_discounted, pa.attributes_price_base_included, pa.attributes_price_onetime,\n\n pa.attributes_price_factor, pa.attributes_price_factor_offset,\n\n pa.attributes_price_factor_onetime, pa.attributes_price_factor_onetime_offset,\n\n pa.attributes_qty_prices, pa.attributes_qty_prices_onetime,\n\n pa.attributes_price_words, pa.attributes_price_words_free,\n\n pa.attributes_price_letters, pa.attributes_price_letters_free,\n\n pad.products_attributes_maxdays, pad.products_attributes_maxcount, pad.products_attributes_filename,\n\n pa.product_attribute_is_free, pa.attributes_discounted\n\n from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa\n\n left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad\n\n on pa.products_attributes_id=pad.products_attributes_id\n\n where pa.products_id = '" . zen_db_input($this->products[$i]['id']) . "'\n\n and pa.options_id = '" . $this->products[$i]['attributes'][$j]['option_id'] . "'\n\n and pa.options_id = popt.products_options_id\n\n and pa.options_values_id = '" . $this->products[$i]['attributes'][$j]['value_id'] . "'\n\n and pa.options_values_id = poval.products_options_values_id\n\n and popt.language_id = '" . $_SESSION['languages_id'] . "'\n\n and poval.language_id = '" . $_SESSION['languages_id'] . "'"; $attributes_values = $db->Execute($attributes_query); } else { $attributes_values = $db->Execute("select popt.products_options_name, poval.products_options_values_name,\n\n pa.options_values_price, pa.price_prefix,\n\n pa.product_attribute_is_free, pa.products_attributes_weight, pa.products_attributes_weight_prefix,\n\n pa.attributes_discounted, pa.attributes_price_base_included, pa.attributes_price_onetime,\n\n pa.attributes_price_factor, pa.attributes_price_factor_offset,\n\n pa.attributes_price_factor_onetime, pa.attributes_price_factor_onetime_offset,\n\n pa.attributes_qty_prices, pa.attributes_qty_prices_onetime,\n\n pa.attributes_price_words, pa.attributes_price_words_free,\n\n pa.attributes_price_letters, pa.attributes_price_letters_free\n\n from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa\n\n where pa.products_id = '" . $this->products[$i]['id'] . "' and pa.options_id = '" . (int) $this->products[$i]['attributes'][$j]['option_id'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . (int) $this->products[$i]['attributes'][$j]['value_id'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $_SESSION['languages_id'] . "' and poval.language_id = '" . $_SESSION['languages_id'] . "'"); } //clr 030714 update insert query. changing to use values form $order->products for products_options_values. $sql_data_array = array('orders_id' => $zf_insert_id, 'orders_products_id' => $order_products_id, 'products_options' => $attributes_values->fields['products_options_name'], 'products_options_values' => $this->products[$i]['attributes'][$j]['value'], 'options_values_price' => $attributes_values->fields['options_values_price'], 'price_prefix' => $attributes_values->fields['price_prefix'], 'product_attribute_is_free' => $attributes_values->fields['product_attribute_is_free'], 'products_attributes_weight' => $attributes_values->fields['products_attributes_weight'], 'products_attributes_weight_prefix' => $attributes_values->fields['products_attributes_weight_prefix'], 'attributes_discounted' => $attributes_values->fields['attributes_discounted'], 'attributes_price_base_included' => $attributes_values->fields['attributes_price_base_included'], 'attributes_price_onetime' => $attributes_values->fields['attributes_price_onetime'], 'attributes_price_factor' => $attributes_values->fields['attributes_price_factor'], 'attributes_price_factor_offset' => $attributes_values->fields['attributes_price_factor_offset'], 'attributes_price_factor_onetime' => $attributes_values->fields['attributes_price_factor_onetime'], 'attributes_price_factor_onetime_offset' => $attributes_values->fields['attributes_price_factor_onetime_offset'], 'attributes_qty_prices' => $attributes_values->fields['attributes_qty_prices'], 'attributes_qty_prices_onetime' => $attributes_values->fields['attributes_qty_prices_onetime'], 'attributes_price_words' => $attributes_values->fields['attributes_price_words'], 'attributes_price_words_free' => $attributes_values->fields['attributes_price_words_free'], 'attributes_price_letters' => $attributes_values->fields['attributes_price_letters'], 'attributes_price_letters_free' => $attributes_values->fields['attributes_price_letters_free'], 'products_options_id' => (int) $this->products[$i]['attributes'][$j]['option_id'], 'products_options_values_id' => (int) $this->products[$i]['attributes'][$j]['value_id'], 'products_prid' => $this->products[$i]['id']); zen_db_perform(TABLE_ORDERS_PRODUCTS_ATTRIBUTES, $sql_data_array); $zco_notifier->notify('NOTIFY_ORDER_DURING_CREATE_ADDED_ATTRIBUTE_LINE_ITEM', $sql_data_array); if (DOWNLOAD_ENABLED == 'true' && isset($attributes_values->fields['products_attributes_filename']) && zen_not_null($attributes_values->fields['products_attributes_filename'])) { $sql_data_array = array('orders_id' => $zf_insert_id, 'orders_products_id' => $order_products_id, 'orders_products_filename' => $attributes_values->fields['products_attributes_filename'], 'download_maxdays' => $attributes_values->fields['products_attributes_maxdays'], 'download_count' => $attributes_values->fields['products_attributes_maxcount'], 'products_prid' => $this->products[$i]['id']); zen_db_perform(TABLE_ORDERS_PRODUCTS_DOWNLOAD, $sql_data_array); $zco_notifier->notify('NOTIFY_ORDER_DURING_CREATE_ADDED_ATTRIBUTE_DOWNLOAD_LINE_ITEM', $sql_data_array); } //clr 030714 changing to use values from $orders->products and adding call to zen_decode_specialchars() // $this->products_ordered_attributes .= "\n\t" . $attributes_values->fields['products_options_name'] . ' ' . $attributes_values->fields['products_options_values_name']; $this->products_ordered_attributes .= "\n\t" . $attributes_values->fields['products_options_name'] . ' ' . zen_decode_specialchars($this->products[$i]['attributes'][$j]['value']); } } //------eof: insert customer-chosen options ---- $zco_notifier->notify('NOTIFY_ORDER_DURING_CREATE_ADD_PRODUCTS', $custom_insertable_text); /* START: ADD MY CUSTOM DETAILS * 1. calculate/prepare custom information to be added to this product entry in order-confirmation. * 2. Add that data to the $this->products_ordered_attributes variable, using this sort of format: * $this->products_ordered_attributes .= {INSERT CUSTOM INFORMATION HERE}; */ $this->products_ordered_attributes .= ''; // $custom_insertable_text; /* END: ADD MY CUSTOM DETAILS */ // update totals counters $this->total_weight += $this->products[$i]['qty'] * $this->products[$i]['weight']; $this->total_tax += zen_calculate_tax($total_products_price, $products_tax) * $this->products[$i]['qty']; $this->total_cost += $total_products_price; $zco_notifier->notify('NOTIFY_ORDER_PROCESSING_ONE_TIME_CHARGES_BEGIN'); // build output for email notification $this->products_ordered .= $this->products[$i]['qty'] . ' x ' . $this->products[$i]['name'] . ($this->products[$i]['model'] != '' ? ' (' . $this->products[$i]['model'] . ') ' : '') . ' = ' . $currencies->display_price($this->products[$i]['final_price'], $this->products[$i]['tax'], $this->products[$i]['qty']) . ($this->products[$i]['onetime_charges'] != 0 ? "\n" . TEXT_ONETIME_CHARGES_EMAIL . $currencies->display_price($this->products[$i]['onetime_charges'], $this->products[$i]['tax'], 1) : '') . $this->products_ordered_attributes . "\n"; $this->products_ordered_html .= '<tr>' . "\n" . '<td class="product-details" align="right" valign="top" width="30">' . $this->products[$i]['qty'] . ' x</td>' . "\n" . '<td class="product-details" valign="top">' . nl2br($this->products[$i]['name']) . ($this->products[$i]['model'] != '' ? ' (' . nl2br($this->products[$i]['model']) . ') ' : '') . "\n" . '<nobr><small><em> ' . nl2br($this->products_ordered_attributes) . '</em></small></nobr></td>' . "\n" . '<td class="product-details-num" valign="top" align="right">' . $currencies->display_price($this->products[$i]['final_price'], $this->products[$i]['tax'], $this->products[$i]['qty']) . ($this->products[$i]['onetime_charges'] != 0 ? '</td></tr>' . "\n" . '<tr><td class="product-details">' . nl2br(TEXT_ONETIME_CHARGES_EMAIL) . '</td>' . "\n" . '<td>' . $currencies->display_price($this->products[$i]['onetime_charges'], $this->products[$i]['tax'], 1) : '') . '</td></tr>' . "\n"; } $order_total_modules->apply_credit(); //ICW ADDED FOR CREDIT CLASS SYSTEM $zco_notifier->notify('NOTIFY_ORDER_AFTER_ORDER_CREATE_ADD_PRODUCTS'); }
$attr_value = htmlspecialchars($products[$i]['attributes_values'][$option], ENT_COMPAT, CHARSET, TRUE); } else { $attributeHiddenField .= zen_draw_hidden_field('id[' . $products[$i]['id'] . '][' . $option . ']', $value); $attr_value = $attributes_values->fields['products_options_values_name']; } $attrArray[$option]['products_options_name'] = $attributes_values->fields['products_options_name']; $attrArray[$option]['options_values_id'] = $value; $attrArray[$option]['products_options_values_name'] = $attr_value; $attrArray[$option]['options_values_price'] = $attributes_values->fields['options_values_price']; $attrArray[$option]['price_prefix'] = $attributes_values->fields['price_prefix']; } } //end foreach [attributes] if (STOCK_CHECK == 'true') { $product_in_cart[zen_get_prid($products[$i]['id'])] += $products[$i]['quantity']; $flagStockCheck = zen_check_stock($products[$i]['id'], $product_in_cart[zen_get_prid($products[$i]['id'])]); if ($flagStockCheck == true) { $flagAnyOutOfStock = true; } } $linkProductsImage = zen_href_link(zen_get_info_page($products[$i]['id']), 'products_id=' . $products[$i]['id']); $linkProductsName = zen_href_link(zen_get_info_page($products[$i]['id']), 'products_id=' . $products[$i]['id']); $productsImage = IMAGE_SHOPPING_CART_STATUS == 1 ? zen_image(DIR_WS_IMAGES . $products[$i]['image'], $products[$i]['name'], IMAGE_SHOPPING_CART_WIDTH, IMAGE_SHOPPING_CART_HEIGHT) : ''; $show_products_quantity_max = zen_get_products_quantity_order_max($products[$i]['id']); $showFixedQuantity = ($show_products_quantity_max == 1 or zen_get_products_qty_box_status($products[$i]['id']) == 0) ? true : false; // $showFixedQuantityAmount = $products[$i]['quantity'] . zen_draw_hidden_field('products_id[]', $products[$i]['id']) . zen_draw_hidden_field('cart_quantity[]', 1); // $showFixedQuantityAmount = $products[$i]['quantity'] . zen_draw_hidden_field('cart_quantity[]', 1); $showFixedQuantityAmount = $products[$i]['quantity'] . zen_draw_hidden_field('cart_quantity[]', $products[$i]['quantity']); $showMinUnits = zen_get_products_quantity_min_units_display($products[$i]['id']); $quantityField = zen_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4"'); $ppe = $products[$i]['final_price'];
$_POST['cart_quantity'][$i] = 0; continue; } if (in_array($_POST['products_id'][$i], is_array($_POST['cart_delete']) ? $_POST['cart_delete'] : array()) or $_POST['cart_quantity'][$i] == 0) { $_SESSION['cart']->remove($_POST['products_id'][$i]); } else { if ((PRODINFO_ATTRIBUTE_PLUGIN_MULTI == 'single_dropdown' || PRODINFO_ATTRIBUTE_PLUGIN_MULTI == 'single_radioset') && (PRODINFO_ATTRIBUTE_DYNAMIC_STATUS == '1' || PRODINFO_ATTRIBUTE_DYNAMIC_STATUS == '2')) { /* Breakdown the attributes into individual attributes to then be able to * feed them into the applicable section(s). * */ } $add_max = zen_get_products_quantity_order_max($_POST['products_id'][$i]); // maximum allowed $query = 'select stock_id from ' . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . ' where products_id = :products_id:'; $query = $db->bindVars($query, ':products_id:', zen_get_prid($_POST['products_id'][$i]), 'integer'); $stock_id = $db->Execute($query, false, false, 0, true); if ((PRODINFO_ATTRIBUTE_PLUGIN_MULTI == 'single_dropdown' || PRODINFO_ATTRIBUTE_PLUGIN_MULTI == 'single_radioset') && (PRODINFO_ATTRIBUTE_DYNAMIC_STATUS == '1' || PRODINFO_ATTRIBUTE_DYNAMIC_STATUS == '2')) { /* Breakdown the attributes into individual attributes to then be able to * feed them into the applicable section(s). * */ } $attributes = $_POST['id'][$_POST['products_id'][$i]] ? $_POST['id'][$_POST['products_id'][$i]] : null; if ($stock_id->RecordCount()) { $productIsSBA[$i] = true; } else { $productIsSBA[$i] = false; } if (!$productIsSBA[$i]) { if ((PRODINFO_ATTRIBUTE_PLUGIN_MULTI == 'single_dropdown' || PRODINFO_ATTRIBUTE_PLUGIN_MULTI == 'single_radioset') && (PRODINFO_ATTRIBUTE_DYNAMIC_STATUS == '1' || PRODINFO_ATTRIBUTE_DYNAMIC_STATUS == '2')) {
function confirmation() { global $cartID, $pagamastardeOrderGeneratedInConfirmation, $pagamastardeCartIDinConfirmation, $customer_id, $languages_id, $order, $order_total_modules, $db; $insert_order = false; if (empty($pagamastardeOrderGeneratedInConfirmation)) { $insert_order = true; } // start - proceso estandar para generar el pedido // // Si el pedido contiene campos extra (NIF, ..) // habria que personalizar donde corresponda, de forma similar a la personalizacion // que se haya hecho en checkout_process.php // La informacion de la sesion activa del usuario se guarda temporalmente en el campo cc_owner // De esta forma se evita la creacion de una tabla adicional para seguimiento de la sesion if ($insert_order == true) { $order_totals = array(); if (is_array($order_total_modules->modules)) { reset($order_total_modules->modules); while (list(, $value) = each($order_total_modules->modules)) { $class = substr($value, 0, strrpos($value, '.')); if ($GLOBALS[$class]->enabled) { for ($i = 0, $n = sizeof($GLOBALS[$class]->output); $i < $n; $i++) { if (zen_not_null($GLOBALS[$class]->output[$i]['title']) && zen_not_null($GLOBALS[$class]->output[$i]['text'])) { $order_totals[] = array('code' => $GLOBALS[$class]->code, 'title' => $GLOBALS[$class]->output[$i]['title'], 'text' => $GLOBALS[$class]->output[$i]['text'], 'value' => $GLOBALS[$class]->output[$i]['value'], 'sort_order' => $GLOBALS[$class]->sort_order); } } } } } //customer id not correctly stored, this line fixes it. $customer_id = $_SESSION['customer_id']; $sql_data_array = array('customers_id' => $customer_id, 'order_total' => $order->info['total'], 'customers_name' => $order->customer['firstname'] . ' ' . $order->customer['lastname'], 'customers_company' => $order->customer['company'], 'customers_street_address' => $order->customer['street_address'], 'customers_suburb' => $order->customer['suburb'], 'customers_city' => $order->customer['city'], 'customers_postcode' => $order->customer['postcode'], 'customers_state' => $order->customer['state'], 'customers_country' => $order->customer['country']['title'], 'customers_telephone' => $order->customer['telephone'], 'customers_email_address' => $order->customer['email_address'], 'customers_address_format_id' => $order->customer['format_id'], 'delivery_name' => $order->delivery['firstname'] . ' ' . $order->delivery['lastname'], 'delivery_company' => $order->delivery['company'], 'delivery_street_address' => $order->delivery['street_address'], 'delivery_suburb' => $order->delivery['suburb'], 'delivery_city' => $order->delivery['city'], 'delivery_postcode' => $order->delivery['postcode'], 'delivery_state' => $order->delivery['state'], 'delivery_country' => $order->delivery['country']['title'], 'delivery_address_format_id' => $order->delivery['format_id'], 'billing_name' => $order->billing['firstname'] . ' ' . $order->billing['lastname'], 'billing_company' => $order->billing['company'], 'billing_street_address' => $order->billing['street_address'], 'billing_suburb' => $order->billing['suburb'], 'billing_city' => $order->billing['city'], 'billing_postcode' => $order->billing['postcode'], 'billing_state' => $order->billing['state'], 'billing_country' => $order->billing['country']['title'], 'billing_address_format_id' => $order->billing['format_id'], 'payment_method' => 'getfinancing', 'payment_module_code' => 'getfinancing', 'cc_type' => $order->info['cc_type'], 'cc_owner' => zen_session_id(), 'cc_number' => $order->info['cc_number'], 'cc_expires' => $order->info['cc_expires'], 'date_purchased' => 'now()', 'orders_status' => $order->info['order_status'], 'currency' => $order->info['currency'], 'currency_value' => $order->info['currency_value'], 'shipping_method' => $order->info['shipping_method'], 'shipping_module_code' => $order->info['shipping_module_code']); zen_db_perform(TABLE_GETFINANCING_ORDERS, $sql_data_array); $insert_id = $db->insert_ID(); //the $_GLOBAL seems to fail. applying patch: $sql_data_array = array('orders_id' => $insert_id, 'title' => 'Total:', 'text' => $order->info['total'], 'value' => $order->info['total'], 'class' => 'ot_total', 'sort_order' => 999); zen_db_perform(TABLE_GETFINANCING_ORDERS_TOTAL, $sql_data_array); for ($i = 0, $n = sizeof($order_totals); $i < $n; $i++) { $sql_data_array = array('orders_id' => $insert_id, 'title' => $order_totals[$i]['title'], 'text' => $order_totals[$i]['text'], 'value' => $order_totals[$i]['value'], 'class' => $order_totals[$i]['code'], 'sort_order' => $order_totals[$i]['sort_order']); zen_db_perform(TABLE_GETFINANCING_ORDERS_TOTAL, $sql_data_array); } for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) { $sql_data_array = array('orders_id' => $insert_id, 'products_id' => zen_get_prid($order->products[$i]['id']), 'products_model' => $order->products[$i]['model'], 'products_name' => $order->products[$i]['name'], 'products_price' => $order->products[$i]['price'], 'final_price' => $order->products[$i]['final_price'], 'products_tax' => $order->products[$i]['tax'], 'products_quantity' => $order->products[$i]['qty']); zen_db_perform(TABLE_GETFINANCING_ORDERS_PRODUCTS, $sql_data_array); $order_products_id = $db->insert_ID(); $attributes_exist = '0'; if (isset($order->products[$i]['attributes'])) { $attributes_exist = '1'; for ($j = 0, $n2 = sizeof($order->products[$i]['attributes']); $j < $n2; $j++) { if (DOWNLOAD_ENABLED == 'true') { $attributes_query = "select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix, pad.products_attributes_maxdays, pad.products_attributes_maxcount , pad.products_attributes_filename\n from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa\n left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad\n on pa.products_attributes_id=pad.products_attributes_id\n where pa.products_id = '" . $order->products[$i]['id'] . "'\n and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "'\n and pa.options_id = popt.products_options_id\n and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "'\n and pa.options_values_id = poval.products_options_values_id"; $attributes = $db->Execute($attributes_query); } else { $attributes = $db->Execute("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . $order->products[$i]['id'] . "' and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "' and pa.options_values_id = poval.products_options_values_id"); } $attributes_values = $attributes->fields; $sql_data_array = array('orders_id' => $insert_id, 'orders_products_id' => $order_products_id, 'products_options' => $attributes_values['products_options_name'], 'products_options_values' => $attributes_values['products_options_values_name'], 'options_values_price' => $attributes_values['options_values_price'], 'price_prefix' => $attributes_values['price_prefix']); zen_db_perform(TABLE_GETFINANCING_ORDERS_PRODUCTS_ATTRIBUTES, $sql_data_array); if (DOWNLOAD_ENABLED == 'true' && isset($attributes_values['products_attributes_filename']) && tep_not_null($attributes_values['products_attributes_filename'])) { $sql_data_array = array('orders_id' => $insert_id, 'orders_products_id' => $order_products_id, 'orders_products_filename' => $attributes_values['products_attributes_filename'], 'download_maxdays' => $attributes_values['products_attributes_maxdays'], 'download_count' => $attributes_values['products_attributes_maxcount']); zen_db_perform(TABLE_GETFINANCING_ORDERS_PRODUCTS_DOWNLOAD, $sql_data_array); } } } } // end - proceso estandar para generar el pedido $pagamastardeOrderGeneratedInConfirmation = $insert_id; $_SESSION['order_number_created'] = $insert_id; //$_SESSION['cart']->cartID = $_SESSION['cart']->generate_cart_id(); } return false; }
function calculate_deductions($order_total) { global $gBitDb, $gBitCustomer, $order; $tax_address = zen_get_tax_locations(); $od_amount['total'] = 0; $od_amount['tax'] = 0; if ($_SESSION['cc_id']) { $coupon = new CommerceVoucher($_SESSION['cc_id']); if ($coupon->load() && $coupon->isRedeemable()) { if ($coupon->getField('coupon_minimum_order') <= $order_total) { if ($coupon->getField('coupon_type') == 'S') { if ($coupon->getField('restrict_to_shipping')) { $shippingMethods = explode(',', $coupon->getField('restrict_to_shipping')); if (in_array($order->info['shipping_method_code'], $shippingMethods)) { $od_amount['total'] = $order->info['shipping_cost']; } } else { $od_amount['total'] = $order->info['shipping_cost']; } $od_amount['type'] = 'S'; } else { if ($coupon->getField('coupon_type') == 'P') { // Max discount is a sum of percentages of valid products $totalDiscount = 0; } else { $totalDiscount = $coupon->getField('coupon_amount') * ($order_total > 0); } $runningDiscount = 0; $runningDiscountQuantity = 0; foreach (array_keys($gBitCustomer->mCart->contents) as $productKey) { $productHash = $gBitCustomer->mCart->getProductHash($productKey); if ($coupon->getField('quantity_max')) { if ($discountQuantity = $coupon->getField('quantity_max') - $runningDiscountQuantity) { if ($discountQuantity > $productHash['products_quantity']) { $discountQuantity = $productHash['products_quantity']; } } } else { $discountQuantity = $productHash['products_quantity']; } if ($productHash && $discountQuantity && $this->is_product_valid($productHash, $_SESSION['cc_id'])) { // _P_ercentage discount if ($coupon->getField('coupon_type') == 'P') { $runningDiscountQuantity += $discountQuantity; $itemDiscount = round($productHash['final_price'] * $discountQuantity * ($coupon->getField('coupon_amount') / 100), 2); $totalDiscount += $itemDiscount; if ($runningDiscount < $totalDiscount) { $runningDiscount += $itemDiscount; } if ($runningDiscount > $totalDiscount) { $runningDiscount = $totalDiscount; $itemDiscount = 0; } switch ($this->calculate_tax) { case 'Credit Note': $tax_rate = zen_get_tax_rate($this->tax_class, $tax_address['country_id'], $tax_address['zone_id']); $tax_desc = zen_get_tax_description($this->tax_class, $tax_address['country_id'], $tax_address['zone_id']); $od_amount[$tax_desc] = $runningDiscount / 100 * $tax_rate; $od_amount['tax'] += $od_amount[$tax_desc]; break; case 'Standard': $ratio = $runningDiscount / $this->get_order_total(); $tax_rate = zen_get_tax_rate($productHash['products_tax_class_id'], $tax_address['country_id'], $tax_address['zone_id']); $tax_desc = zen_get_tax_description($productHash['products_tax_class_id'], $tax_address['country_id'], $tax_address['zone_id']); if ($tax_rate > 0) { if (empty($od_amount[$tax_desc])) { $od_amount[$tax_desc] = 0; } $od_amount[$tax_desc] += $productHash['final_price'] * $discountQuantity * $tax_rate / 100 * $ratio; $od_amount['tax'] += $od_amount[$tax_desc]; } break; } // _F_ixed discount } elseif ($coupon->getField('coupon_type') == 'F') { switch ($this->calculate_tax) { case 'Credit Note': $tax_rate = zen_get_tax_rate($this->tax_class, $tax_address['country_id'], $tax_address['zone_id']); $tax_desc = zen_get_tax_description($this->tax_class, $tax_address['country_id'], $tax_address['zone_id']); $od_amount[$tax_desc] = $runningDiscount / 100 * $tax_rate; $od_amount['tax'] += $od_amount[$tax_desc]; break; case 'Standard': $ratio = $runningDiscount / $this->get_order_total(); $t_prid = zen_get_prid($productKey); $cc_result = $gBitDb->query("select `products_tax_class_id` from " . TABLE_PRODUCTS . " where `products_id` = ?", array($t_prid)); if ($this->is_product_valid($productHash, $_SESSION['cc_id'])) { if ($runningDiscount < $totalDiscount) { $runningDiscount += $productHash['final_price'] * $discountQuantity; } if ($runningDiscount > $totalDiscount) { $runningDiscount = $totalDiscount; } $tax_rate = zen_get_tax_rate($cc_result->fields['products_tax_class_id'], $tax_address['country_id'], $tax_address['zone_id']); $tax_desc = zen_get_tax_description($cc_result->fields['products_tax_class_id'], $tax_address['country_id'], $tax_address['zone_id']); if ($tax_rate > 0) { if (empty($od_amount[$tax_desc])) { $od_amount[$tax_desc] = 0; } $od_amount[$tax_desc] += $productHash['final_price'] * $discountQuantity * $tax_rate / 100 * $ratio; $od_amount['tax'] += $od_amount[$tax_desc]; } } break; } } } } $od_amount['total'] = $runningDiscount; if ($od_amount['total'] > $order_total) { $od_amount['total'] = $order_total; } } } } } return $od_amount; }
function updateNotifyOrderProcessingStockDecrementEnd(&$callingClass, $notifier, $paramsArray) { //Need to modify the email that is going out regarding low-stock. //paramsArray is $i at time of development. if ($this->_orderIsSBA) { // Only take SBA action on SBA tracked product mc12345678 12-18-2015 if ($callingClass->email_low_stock == '' && $callingClass->doStockDecrement && $this->_stock_values->RecordCount() > 0 && $this->_attribute_stock_left <= STOCK_REORDER_LEVEL) { // kuroi: trigger and details for attribute low stock email $callingClass->email_low_stock .= 'ID# ' . zen_get_prid($this->_productI['id']) . ', model# ' . $this->_productI['model'] . ', customid ' . $this->_productI['customid'] . ', name ' . $this->_productI['name'] . ', '; foreach ($this->_productI['attributes'] as $attributes) { $callingClass->email_low_stock .= $attributes['option'] . ': ' . $attributes['value'] . ', '; } $callingClass->email_low_stock .= 'Stock: ' . $this->_attribute_stock_left . "\n\n"; // kuroi: End Stock by Attribute additions } } }
function zen_get_customid($products_id, $attributes = null) { global $db; $customid_model_query = null; $customid_query = null; $products_id = zen_get_prid($products_id); // check if there are attributes for this product $stock_has_attributes_query = 'select products_attributes_id from ' . TABLE_PRODUCTS_ATTRIBUTES . ' where products_id = :products_id:'; $stock_has_attributes_query = $db->bindVars($stock_has_attributes_query, ':products_id:', $products_id, 'integer'); $stock_has_attributes = $db->Execute($stock_has_attributes_query); if ($stock_has_attributes->RecordCount() < 1) { //if no attributes return products_model $no_attribute_stock_query = 'select products_model from ' . TABLE_PRODUCTS . ' where products_id = :products_id:'; $no_attribute_stock_query = $db->bindVars($no_attribute_stock_query, ':products_id:', $products_id, 'integer'); $customid = $db->Execute($no_attribute_stock_query); return $customid->fields['products_model']; } else { if (is_array($attributes) and sizeof($attributes) > 0) { // check if attribute stock values have been set for the product // if there are will we continue, otherwise we'll use product level data $attribute_stock = $db->Execute("select stock_id \n\t\t\t\t\t\t\t \t\t\t\t\tfrom " . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . " \n\t\t\t\t\t\t\t \t\t\t\t\twhere products_id = " . (int) $products_id . ";"); if ($attribute_stock->RecordCount() > 0) { // search for details for the particular attributes combination $first_search = 'where options_values_id in ("' . implode('","', $attributes) . '")'; // obtain the attribute ids $query = 'select products_attributes_id from ' . TABLE_PRODUCTS_ATTRIBUTES . ' ' . $first_search . ' and products_id=' . $products_id . ' order by products_attributes_id;'; $attributes_new = $db->Execute($query); while (!$attributes_new->EOF) { $stock_attributes[] = $attributes_new->fields['products_attributes_id']; $attributes_new->MoveNext(); } $stock_attributes_comb = implode(',', $stock_attributes); } //Get product model $customid_model_query = 'select products_model from ' . TABLE_PRODUCTS . ' where products_id = ' . (int) $products_id . ';'; //Get custom id as products_model $customid_query = 'select customid as products_model from ' . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . ' where products_id = :products_id: and stock_attributes in (:stock_attributes:);'; $customid_query = $db->bindVars($customid_query, ':products_id:', $products_id, 'integer'); $customid_query = $db->bindVars($customid_query, ':stock_attributes:', $stock_attributes_comb, 'string'); $customid = $db->Execute($customid_query); //moved to inside this loop as for some reason it has made if (!$customid->RecordCount()) { // if a customid does not exist for the combination of attributes then perhaps the attributes are individually listed. $customid_query = 'select customid as products_model from ' . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . ' where products_id = :products_id: and stock_attributes in (:stock_attributes:)'; $customid_query = $db->bindVars($customid_query, ':products_id:', $products_id, 'integer'); $customid_query = $db->bindVars($customid_query, ':stock_attributes:', $stock_attributes_comb, 'passthru'); $customid = $db->Execute($customid_query); //moved to inside this loop as for some reason it has made } } // $customid = $db->Execute($customid_query); if ($customid->fields['products_model']) { //Test to see if a custom ID exists //if there are custom IDs with the attribute, then return them. $multiplecid = null; //mc12345678: Alternative to the below would be to build an array of "products_model" then implode // the array on ', '... Both methods would require stepping through each of the // returned values to build the desired structure. The below does all of the // implode in one swoop, though does not account for some of the individual items having // a customid while others do not and thus could get x, y, , w, , z as an example. // Either this is something identified up front, is prevented from happening at all, or // is controllable through some form of "switch". The maximum flexibility of this is // covered by adding an if statement to the below, otherwise if going to build an array // to then be imploded, separate action would need to take place to eliminate the "blanks". while (!$customid->EOF) { $multiplecid .= $customid->fields['products_model'] . ', '; $customid->MoveNext(); } $multiplecid = rtrim($multiplecid, ', '); //return result for display return $multiplecid; } else { $customid = null; //This is used as a fall-back when custom ID is set to be displayed but no attribute is available. //Get product model $customid_model_query = 'select products_model from ' . TABLE_PRODUCTS . ' where products_id = :products_id:'; $customid_model_query = $db->bindVars($customid_model_query, ':products_id:', $products_id, 'integer'); $customid = $db->Execute($customid_model_query); //return result for display return $customid->fields['products_model']; } return; //nothing to return, should never reach this return } }
function in_cart_check($check_what, $check_value = '1') { // if nothing is in cart return 0 if (!is_array($this->contents)) { return 0; } // compute total quantity for field $in_cart_check_qty = 0; reset($this->contents); while (list($productsKey, ) = each($this->contents)) { $testing_id = zen_get_prid($productsKey); // check if field it true $product_check = $this->mDb->getOne("select " . $check_what . " as `check_it` from " . TABLE_PRODUCTS . " where `products_id` = ?", array($testing_id)); if ($product_check == $check_value) { $in_cart_check_qty += $this->contents[$productsKey]['products_quantity']; } } return $in_cart_check_qty; }
function create_add_products($zf_insert_id, $zf_mode = false) { global $db, $currencies, $order_total_modules, $order_totals; // initialized for the email confirmation $this->products_ordered = ''; $this->products_ordered_html = ''; $this->subtotal = 0; $this->total_tax = 0; // lowstock email report $this->email_low_stock = ''; for ($i = 0, $n = sizeof($this->products); $i < $n; $i++) { // Stock Update - Joao Correia if (STOCK_LIMITED == 'true') { if (DOWNLOAD_ENABLED == 'true') { $stock_query_raw = "SELECT products_quantity, pad.products_attributes_filename\r\n FROM " . TABLE_PRODUCTS . " p\r\n LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES . " pa\r\n ON p.products_id=pa.products_id\r\n LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad\r\n ON pa.products_attributes_id=pad.products_attributes_id\r\n WHERE p.products_id = '" . zen_get_prid($this->products[$i]['id']) . "'"; // Will work with only one option for downloadable products // otherwise, we have to build the query dynamically with a loop $products_attributes = $this->products[$i]['attributes']; if (is_array($products_attributes)) { $stock_query_raw .= " AND pa.options_id = '" . $products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . $products_attributes[0]['value_id'] . "'"; } $stock_values = $db->Execute($stock_query_raw); } else { $stock_values = $db->Execute("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . zen_get_prid($this->products[$i]['id']) . "'"); } if ($stock_values->RecordCount() > 0) { // do not decrement quantities if products_attributes_filename exists if (DOWNLOAD_ENABLED != 'true' || !$stock_values->fields['products_attributes_filename']) { $stock_left = $stock_values->fields['products_quantity'] - $this->products[$i]['qty']; $this->products[$i]['stock_reduce'] = $this->products[$i]['qty']; } else { $stock_left = $stock_values->fields['products_quantity']; } // $this->products[$i]['stock_value'] = $stock_values->fields['products_quantity']; $db->Execute("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . zen_get_prid($this->products[$i]['id']) . "'"); // if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT == 'false') ) { if ($stock_left < 1) { // only set status to off when not displaying sold out if (SHOW_PRODUCTS_SOLD_OUT == '0') { $db->Execute("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . zen_get_prid($this->products[$i]['id']) . "'"); } } // for low stock email if ($stock_left <= STOCK_REORDER_LEVEL) { // WebMakers.com Added: add to low stock email $this->email_low_stock .= 'ID# ' . zen_get_prid($this->products[$i]['id']) . "\t\t" . $this->products[$i]['model'] . "\t\t" . $this->products[$i]['name'] . "\t\t" . ' Qty Left: ' . $stock_left . "\n"; } } } // Update products_ordered (for bestsellers list) // $db->Execute("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . zen_get_prid($order->products[$i]['id']) . "'"); $db->Execute("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%f', $this->products[$i]['qty']) . " where products_id = '" . zen_get_prid($this->products[$i]['id']) . "'"); $sql_data_array = array('orders_id' => $zf_insert_id, 'products_id' => zen_get_prid($this->products[$i]['id']), 'products_model' => $this->products[$i]['model'], 'products_name' => $this->products[$i]['name'], 'products_price' => $this->products[$i]['price'], 'final_price' => $this->products[$i]['final_price'], 'onetime_charges' => $this->products[$i]['onetime_charges'], 'products_tax' => $this->products[$i]['tax'], 'products_quantity' => $this->products[$i]['qty'], 'products_priced_by_attribute' => $this->products[$i]['products_priced_by_attribute'], 'product_is_free' => $this->products[$i]['product_is_free'], 'products_discount_type' => $this->products[$i]['products_discount_type'], 'products_discount_type_from' => $this->products[$i]['products_discount_type_from'], 'products_prid' => $this->products[$i]['id']); zen_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array); $order_products_id = $db->Insert_ID(); $order_total_modules->update_credit_account($i); //ICW ADDED FOR CREDIT CLASS SYSTEM //------insert customer choosen option to order-------- $attributes_exist = '0'; $this->products_ordered_attributes = ''; if (isset($this->products[$i]['attributes'])) { $attributes_exist = '1'; for ($j = 0, $n2 = sizeof($this->products[$i]['attributes']); $j < $n2; $j++) { if (DOWNLOAD_ENABLED == 'true') { $attributes_query = "select popt.products_options_name, poval.products_options_values_name,\r\n pa.options_values_price, pa.price_prefix,\r\n pa.product_attribute_is_free, pa.products_attributes_weight, pa.products_attributes_weight_prefix,\r\n pa.attributes_discounted, pa.attributes_price_base_included, pa.attributes_price_onetime,\r\n pa.attributes_price_factor, pa.attributes_price_factor_offset,\r\n pa.attributes_price_factor_onetime, pa.attributes_price_factor_onetime_offset,\r\n pa.attributes_qty_prices, pa.attributes_qty_prices_onetime,\r\n pa.attributes_price_words, pa.attributes_price_words_free,\r\n pa.attributes_price_letters, pa.attributes_price_letters_free,\r\n pad.products_attributes_maxdays, pad.products_attributes_maxcount, pad.products_attributes_filename,\r\n pa.product_attribute_is_free, pa.attributes_discounted\r\n from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa\r\n left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad\r\n on pa.products_attributes_id=pad.products_attributes_id\r\n where pa.products_id = '" . zen_db_input($this->products[$i]['id']) . "'\r\n and pa.options_id = '" . $this->products[$i]['attributes'][$j]['option_id'] . "'\r\n and pa.options_id = popt.products_options_id\r\n and pa.options_values_id = '" . $this->products[$i]['attributes'][$j]['value_id'] . "'\r\n and pa.options_values_id = poval.products_options_values_id\r\n and popt.language_id = '" . $_SESSION['languages_id'] . "'\r\n and poval.language_id = '" . $_SESSION['languages_id'] . "'"; $attributes_values = $db->Execute($attributes_query); } else { $attributes_values = $db->Execute("select popt.products_options_name, poval.products_options_values_name,\r\n pa.options_values_price, pa.price_prefix,\r\n pa.product_attribute_is_free, pa.products_attributes_weight, pa.products_attributes_weight_prefix,\r\n pa.attributes_discounted, pa.attributes_price_base_included, pa.attributes_price_onetime,\r\n pa.attributes_price_factor, pa.attributes_price_factor_offset,\r\n pa.attributes_price_factor_onetime, pa.attributes_price_factor_onetime_offset,\r\n pa.attributes_qty_prices, pa.attributes_qty_prices_onetime,\r\n pa.attributes_price_words, pa.attributes_price_words_free,\r\n pa.attributes_price_letters, pa.attributes_price_letters_free\r\n from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa\r\n where pa.products_id = '" . $this->products[$i]['id'] . "' and pa.options_id = '" . $this->products[$i]['attributes'][$j]['option_id'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . $this->products[$i]['attributes'][$j]['value_id'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $_SESSION['languages_id'] . "' and poval.language_id = '" . $_SESSION['languages_id'] . "'"); } //clr 030714 update insert query. changing to use values form $order->products for products_options_values. $sql_data_array = array('orders_id' => $zf_insert_id, 'orders_products_id' => $order_products_id, 'products_options' => $attributes_values->fields['products_options_name'], 'products_options_values' => $this->products[$i]['attributes'][$j]['value'], 'options_values_price' => $attributes_values->fields['options_values_price'], 'price_prefix' => $attributes_values->fields['price_prefix'], 'product_attribute_is_free' => $attributes_values->fields['product_attribute_is_free'], 'products_attributes_weight' => $attributes_values->fields['products_attributes_weight'], 'products_attributes_weight_prefix' => $attributes_values->fields['products_attributes_weight_prefix'], 'attributes_discounted' => $attributes_values->fields['attributes_discounted'], 'attributes_price_base_included' => $attributes_values->fields['attributes_price_base_included'], 'attributes_price_onetime' => $attributes_values->fields['attributes_price_onetime'], 'attributes_price_factor' => $attributes_values->fields['attributes_price_factor'], 'attributes_price_factor_offset' => $attributes_values->fields['attributes_price_factor_offset'], 'attributes_price_factor_onetime' => $attributes_values->fields['attributes_price_factor_onetime'], 'attributes_price_factor_onetime_offset' => $attributes_values->fields['attributes_price_factor_onetime_offset'], 'attributes_qty_prices' => $attributes_values->fields['attributes_qty_prices'], 'attributes_qty_prices_onetime' => $attributes_values->fields['attributes_qty_prices_onetime'], 'attributes_price_words' => $attributes_values->fields['attributes_price_words'], 'attributes_price_words_free' => $attributes_values->fields['attributes_price_words_free'], 'attributes_price_letters' => $attributes_values->fields['attributes_price_letters'], 'attributes_price_letters_free' => $attributes_values->fields['attributes_price_letters_free'], 'products_options_id' => $this->products[$i]['attributes'][$j]['option_id'], 'products_options_values_id' => $this->products[$i]['attributes'][$j]['value_id'], 'products_prid' => $this->products[$i]['id']); zen_db_perform(TABLE_ORDERS_PRODUCTS_ATTRIBUTES, $sql_data_array); if (DOWNLOAD_ENABLED == 'true' && isset($attributes_values->fields['products_attributes_filename']) && zen_not_null($attributes_values->fields['products_attributes_filename'])) { $sql_data_array = array('orders_id' => $zf_insert_id, 'orders_products_id' => $order_products_id, 'orders_products_filename' => $attributes_values->fields['products_attributes_filename'], 'download_maxdays' => $attributes_values->fields['products_attributes_maxdays'], 'download_count' => $attributes_values->fields['products_attributes_maxcount'], 'products_prid' => $this->products[$i]['id']); zen_db_perform(TABLE_ORDERS_PRODUCTS_DOWNLOAD, $sql_data_array); } //clr 030714 changing to use values from $orders->products and adding call to zen_decode_specialchars() // $this->products_ordered_attributes .= "\n\t" . $attributes_values->fields['products_options_name'] . ' ' . $attributes_values->fields['products_options_values_name']; $this->products_ordered_attributes .= "\n\t" . $attributes_values->fields['products_options_name'] . ' ' . zen_decode_specialchars($this->products[$i]['attributes'][$j]['value']); } } //------insert customer choosen option eof ---- $this->total_weight += $this->products[$i]['qty'] * $this->products[$i]['weight']; $this->total_tax += zen_calculate_tax($total_products_price, $products_tax) * $this->products[$i]['qty']; $this->total_cost += $total_products_price; // include onetime charges $this->products_ordered .= $this->products[$i]['qty'] . ' x ' . $this->products[$i]['name'] . ($this->products[$i]['model'] != '' ? ' (' . $this->products[$i]['model'] . ') ' : '') . ' = ' . $currencies->display_price($this->products[$i]['final_price'], $this->products[$i]['tax'], $this->products[$i]['qty']) . ($this->products[$i]['onetime_charges'] != 0 ? "\n" . TEXT_ONETIME_CHARGES_EMAIL . $currencies->display_price($this->products[$i]['onetime_charges'], $this->products[$i]['tax'], 1) : '') . $this->products_ordered_attributes . "\n"; $this->products_ordered_html .= '<tr>' . '<td class="product-details" align="right" valign="top" width="30">' . $this->products[$i]['qty'] . ' x</td>' . '<td class="product-details" valign="top">' . $this->products[$i]['name'] . ($this->products[$i]['model'] != '' ? ' (' . $this->products[$i]['model'] . ') ' : '') . '<nobr><small><em> ' . $this->products_ordered_attributes . '</em></small></nobr></td>' . '<td class="product-details-num" valign="top" align="right">' . $currencies->display_price($this->products[$i]['final_price'], $this->products[$i]['tax'], $this->products[$i]['qty']) . ($this->products[$i]['onetime_charges'] != 0 ? '</td></tr><tr><td class="product-details">' . TEXT_ONETIME_CHARGES_EMAIL . '</td>' . '<td>' . $currencies->display_price($this->products[$i]['onetime_charges'], $this->products[$i]['tax'], 1) : '') . '</td></tr>'; } $order_total_modules->apply_credit(); //ICW ADDED FOR CREDIT CLASS SYSTEM }
function eo_add_product_to_order($order_id, $product) { global $db, $order; // Stock Update - Joao Correia if (STOCK_LIMITED == 'true') { if (DOWNLOAD_ENABLED == 'true') { $stock_query_raw = "select p.products_quantity, pad.products_attributes_filename, p.product_is_always_free_shipping\n\t\t\tfrom " . TABLE_PRODUCTS . " p\n\t\t\tleft join " . TABLE_PRODUCTS_ATTRIBUTES . " pa\n\t\t\ton p.products_id=pa.products_id\n\t\t\tleft join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad\n\t\t\ton pa.products_attributes_id=pad.products_attributes_id\n\t\t\tWHERE p.products_id = '" . zen_get_prid($product['id']) . "'"; // Will work with only one option for downloadable products // otherwise, we have to build the query dynamically with a loop $products_attributes = $product['attributes']; if (is_array($products_attributes)) { $stock_query_raw .= " AND pa.options_id = '" . $products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . $products_attributes[0]['value_id'] . "'"; } $stock_values = $db->Execute($stock_query_raw); } else { $stock_values = $db->Execute("select * from " . TABLE_PRODUCTS . " where products_id = '" . zen_get_prid($product['id']) . "'"); } if ($stock_values->RecordCount() > 0) { // do not decrement quantities if products_attributes_filename exists if (DOWNLOAD_ENABLED != 'true' || $stock_values->fields['product_is_always_free_shipping'] == 2 || !$stock_values->fields['products_attributes_filename']) { $stock_left = $stock_values->fields['products_quantity'] - $product['qty']; $product['stock_reduce'] = $product['qty']; } else { $stock_left = $stock_values->fields['products_quantity']; } $db->Execute("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . zen_get_prid($product['id']) . "'"); if ($stock_left <= 0) { // only set status to off when not displaying sold out if (SHOW_PRODUCTS_SOLD_OUT == '0') { $db->Execute("update " . TABLE_PRODUCTS . " set products_status = 0 where products_id = '" . zen_get_prid($product['id']) . "'"); } } // for low stock email if ($stock_left <= STOCK_REORDER_LEVEL) { // WebMakers.com Added: add to low stock email $order->email_low_stock .= 'ID# ' . zen_get_prid($product['id']) . "\t\t" . $product['model'] . "\t\t" . $product['name'] . "\t\t" . ' Qty Left: ' . $stock_left . "\n"; } } } // Update products_ordered (for bestsellers list) $db->Execute("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%f', $product['qty']) . " where products_id = '" . zen_get_prid($product['id']) . "'"); $sql_data_array = array('orders_id' => (int) $order_id, 'products_id' => zen_get_prid($product['id']), 'products_model' => $product['model'], 'products_name' => $product['name'], 'products_price' => $product['price'], 'final_price' => $product['final_price'], 'onetime_charges' => $product['onetime_charges'], 'products_tax' => $product['tax'], 'products_quantity' => $product['qty'], 'products_priced_by_attribute' => $product['products_priced_by_attribute'], 'product_is_free' => $product['product_is_free'], 'products_discount_type' => $product['products_discount_type'], 'products_discount_type_from' => $product['products_discount_type_from'], 'products_prid' => $product['id']); zen_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array); $order_products_id = $db->Insert_ID(); //------ bof: insert customer-chosen options to order-------- $attributes_exist = '0'; if (isset($product['attributes'])) { $attributes_exist = '1'; for ($j = 0, $n2 = sizeof($product['attributes']); $j < $n2; $j++) { if (DOWNLOAD_ENABLED == 'true') { $attributes_query = "select popt.products_options_name, poval.products_options_values_name,\n\t\t\t\tpa.options_values_price, pa.price_prefix,\n\t\t\t\tpa.product_attribute_is_free, pa.products_attributes_weight, pa.products_attributes_weight_prefix,\n\t\t\t\tpa.attributes_discounted, pa.attributes_price_base_included, pa.attributes_price_onetime,\n\t\t\t\tpa.attributes_price_factor, pa.attributes_price_factor_offset,\n\t\t\t\tpa.attributes_price_factor_onetime, pa.attributes_price_factor_onetime_offset,\n\t\t\t\tpa.attributes_qty_prices, pa.attributes_qty_prices_onetime,\n\t\t\t\tpa.attributes_price_words, pa.attributes_price_words_free,\n\t\t\t\tpa.attributes_price_letters, pa.attributes_price_letters_free,\n\t\t\t\tpad.products_attributes_maxdays, pad.products_attributes_maxcount, pad.products_attributes_filename\n\t\t\t\tfrom " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa\n\t\t\t\tleft join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad\n\t\t\t\ton pa.products_attributes_id=pad.products_attributes_id\n\t\t\t\twhere pa.products_id = '" . zen_db_input($product['id']) . "'\n\t\t\t\tand pa.options_id = '" . $product['attributes'][$j]['option_id'] . "'\n\t\t\t\tand pa.options_id = popt.products_options_id\n\t\t\t\tand pa.options_values_id = '" . $product['attributes'][$j]['value_id'] . "'\n\t\t\t\tand pa.options_values_id = poval.products_options_values_id\n\t\t\t\tand popt.language_id = '" . $_SESSION['languages_id'] . "'\n\t\t\t\tand poval.language_id = '" . $_SESSION['languages_id'] . "'"; $attributes_values = $db->Execute($attributes_query); } else { $attributes_values = $db->Execute("select popt.products_options_name, poval.products_options_values_name,\n\t\t\t\t\t\tpa.options_values_price, pa.price_prefix,\n\t\t\t\t\t\tpa.product_attribute_is_free, pa.products_attributes_weight, pa.products_attributes_weight_prefix,\n\t\t\t\t\t\tpa.attributes_discounted, pa.attributes_price_base_included, pa.attributes_price_onetime,\n\t\t\t\t\t\tpa.attributes_price_factor, pa.attributes_price_factor_offset,\n\t\t\t\t\t\tpa.attributes_price_factor_onetime, pa.attributes_price_factor_onetime_offset,\n\t\t\t\t\t\tpa.attributes_qty_prices, pa.attributes_qty_prices_onetime,\n\t\t\t\t\t\tpa.attributes_price_words, pa.attributes_price_words_free,\n\t\t\t\t\t\tpa.attributes_price_letters, pa.attributes_price_letters_free\n\t\t\t\t\t\tfrom " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa\n\t\t\t\t\t\twhere pa.products_id = '" . $product['id'] . "' and pa.options_id = '" . (int) $product['attributes'][$j]['option_id'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . (int) $product['attributes'][$j]['value_id'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $_SESSION['languages_id'] . "' and poval.language_id = '" . $_SESSION['languages_id'] . "'"); } //clr 030714 update insert query. changing to use values form $order->products for products_options_values. $sql_data_array = array('orders_id' => (int) $order_id, 'orders_products_id' => (int) $order_products_id, 'products_options' => $attributes_values->fields['products_options_name'], 'products_options_values' => $product['attributes'][$j]['value'], 'options_values_price' => $attributes_values->fields['options_values_price'], 'price_prefix' => $attributes_values->fields['price_prefix'], 'product_attribute_is_free' => $attributes_values->fields['product_attribute_is_free'], 'products_attributes_weight' => $attributes_values->fields['products_attributes_weight'], 'products_attributes_weight_prefix' => $attributes_values->fields['products_attributes_weight_prefix'], 'attributes_discounted' => $attributes_values->fields['attributes_discounted'], 'attributes_price_base_included' => $attributes_values->fields['attributes_price_base_included'], 'attributes_price_onetime' => $attributes_values->fields['attributes_price_onetime'], 'attributes_price_factor' => $attributes_values->fields['attributes_price_factor'], 'attributes_price_factor_offset' => $attributes_values->fields['attributes_price_factor_offset'], 'attributes_price_factor_onetime' => $attributes_values->fields['attributes_price_factor_onetime'], 'attributes_price_factor_onetime_offset' => $attributes_values->fields['attributes_price_factor_onetime_offset'], 'attributes_qty_prices' => $attributes_values->fields['attributes_qty_prices'], 'attributes_qty_prices_onetime' => $attributes_values->fields['attributes_qty_prices_onetime'], 'attributes_price_words' => $attributes_values->fields['attributes_price_words'], 'attributes_price_words_free' => $attributes_values->fields['attributes_price_words_free'], 'attributes_price_letters' => $attributes_values->fields['attributes_price_letters'], 'attributes_price_letters_free' => $attributes_values->fields['attributes_price_letters_free'], 'products_options_id' => (int) $product['attributes'][$j]['option_id'], 'products_options_values_id' => (int) $product['attributes'][$j]['value_id'], 'products_prid' => $product['id']); zen_db_perform(TABLE_ORDERS_PRODUCTS_ATTRIBUTES, $sql_data_array); if (DOWNLOAD_ENABLED == 'true' && isset($attributes_values->fields['products_attributes_filename']) && zen_not_null($attributes_values->fields['products_attributes_filename'])) { $sql_data_array = array('orders_id' => (int) $order_id, 'orders_products_id' => (int) $order_products_id, 'orders_products_filename' => $attributes_values->fields['products_attributes_filename'], 'download_maxdays' => $attributes_values->fields['products_attributes_maxdays'], 'download_count' => $attributes_values->fields['products_attributes_maxcount'], 'products_prid' => $product['id']); zen_db_perform(TABLE_ORDERS_PRODUCTS_DOWNLOAD, $sql_data_array); } } } $order->products[] = $product; return $product; }
/** * Parses the paramaters for a page to generate a valid url for the page. * * @param string $page the name of the page * @param string $params any paramaters for the page * @param string $separator the separator to use between the link and this paramater (if needed) * @return Ambigous <string, unknown> */ function parse_parameters($page, $params, &$separator) { $p = @explode('&', $params); sort($p); // We need cPath to always appear before id's $container = array(); foreach ($p as $index => $valuepair) { $p2 = @explode('=', $valuepair); switch ($p2[0]) { case 'products_id': // Make sure if uprid is passed it is converted to the correct pid $p2[1] = zen_get_prid($p2[1]); // If a cPath was present we need to determine the immediate parent cid $cID = null; if (array_key_exists('cPath', $container)) { $cID = strrpos($container['cPath'], '_'); if ($cID !== false) { $cID = substr($container['cPath'], $cID + 1); } else { $cID = $container['cPath']; } if (SEO_URL_CATEGORY_DIR != 'off' || SEO_URL_CPATH != 'auto') { unset($container['cPath']); } } switch (true) { case $page == FILENAME_PRODUCT_REVIEWS: $url = $this->make_url($page, $this->get_product_name($p2[1], $cID), 'products_id_review', $p2[1], SEO_URL_END, $separator); break; case $page == FILENAME_PRODUCT_REVIEWS_INFO: $url = $this->make_url($page, $this->get_product_name($p2[1], $cID), 'products_id_review_info', $p2[1], SEO_URL_END, $separator); break; case $page == FILENAME_DEFAULT: $container[$p2[0]] = $p2[1]; break; case $page == FILENAME_PRODUCT_INFO: default: $url = $this->make_url($page, $this->get_product_name($p2[1], $cID), $p2[0], $p2[1], SEO_URL_END, $separator); break; } # end switch break; case 'cPath': switch (true) { case $page == FILENAME_DEFAULT: // Change $p2[1] to the actual category id $tmp = strrpos($p2[1], '_'); if ($tmp !== false) { $p2[1] = substr($p2[1], $tmp + 1); } $category = $this->get_category_name($p2[1]); if (SEO_URL_CATEGORY_DIR == 'off') { $url = $this->make_url($page, $category, $p2[0], $p2[1], SEO_URL_END, $separator); } else { $url = $this->make_url($page, $category, $p2[0], $p2[1], '/', $separator); } unset($category); break; default: $container[$p2[0]] = $p2[1]; break; } # end switch break; case 'manufacturers_id': switch (true) { case $page == FILENAME_DEFAULT && !$this->is_cPath_string($params) && !$this->is_product_string($params): $url = $this->make_url($page, $this->get_manufacturer_name($p2[1]), $p2[0], $p2[1], SEO_URL_END, $separator); break; case $page == FILENAME_PRODUCT_INFO: break; default: $container[$p2[0]] = $p2[1]; break; } # end switch break; case 'pID': switch (true) { case $page == FILENAME_POPUP_IMAGE: $url = $this->make_url($page, $this->get_product_name($p2[1]), $p2[0], $p2[1], SEO_URL_END, $separator); break; default: $container[$p2[0]] = $p2[1]; break; } # end switch break; case 'id': // EZ-Pages switch (true) { case $page == FILENAME_EZPAGES: $url = $this->make_url($page, $this->get_ezpages_name($p2[1]), $p2[0], $p2[1], SEO_URL_END, $separator); break; default: $container[$p2[0]] = $p2[1]; break; } # end switch break; default: $container[$p2[0]] = $p2[1]; break; } # end switch } # end foreach $p $url = isset($url) ? $url : $page . SEO_URL_END; if (sizeof($container) > 0) { if ($imploded_params = $this->implode_assoc($container)) { $url .= $separator . zen_output_string($imploded_params); $separator = '&'; } } return $url; }
} $attrArray[$option]['products_options_name'] = $attributes_values->fields['products_options_name']; $attrArray[$option]['options_values_id'] = $value; $attrArray[$option]['products_options_values_name'] = zen_output_string_protected($attr_value); $attrArray[$option]['options_values_price'] = $attributes_values->fields['options_values_price']; $attrArray[$option]['price_prefix'] = $attributes_values->fields['price_prefix']; } } //end foreach [attributes] if (STOCK_CHECK == 'true') { $flagStockCheck = zen_check_stock($products[$i]['id'], $products[$i]['quantity']); if ($flagStockCheck == true) { $flagAnyOutOfStock = true; } } $realPid = zen_get_prid($products[$i]['id']); $linkProductsImage = zen_href_link(zen_get_info_page($realPid), 'products_id=' . $realPid); $linkProductsName = zen_href_link(zen_get_info_page($realPid), 'products_id=' . $realPid); $productsImage = IMAGE_SHOPPING_CART_STATUS == 1 ? zen_image(DIR_WS_IMAGES . $products[$i]['image'], $products[$i]['name'], IMAGE_SHOPPING_CART_WIDTH, IMAGE_SHOPPING_CART_HEIGHT) : ''; $show_products_quantity_max = zen_get_products_quantity_order_max($products[$i]['id']); $showFixedQuantity = ($show_products_quantity_max == 1 or zen_get_products_qty_box_status($products[$i]['id']) == 0) ? true : false; // $showFixedQuantityAmount = $products[$i]['quantity'] . zen_draw_hidden_field('products_id[]', $products[$i]['id']) . zen_draw_hidden_field('cart_quantity[]', 1); // $showFixedQuantityAmount = $products[$i]['quantity'] . zen_draw_hidden_field('cart_quantity[]', 1); $showFixedQuantityAmount = $products[$i]['quantity'] . zen_draw_hidden_field('cart_quantity[]', $products[$i]['quantity']); $showMinUnits = zen_get_products_quantity_min_units_display($products[$i]['id']); //$quantityField = zen_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4"'); $quantityField = zen_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4"', 'text'); $buttonUpdate = ((SHOW_SHOPPING_CART_UPDATE == 1 or SHOW_SHOPPING_CART_UPDATE == 3) ? zen_image_submit(ICON_IMAGE_UPDATE, ICON_UPDATE_ALT) : '') . zen_draw_hidden_field('products_id[]', $products[$i]['id']); $productsPrice = $currencies->display_price($products[$i]['final_price'], zen_get_tax_rate($products[$i]['tax_class_id']), $products[$i]['quantity']) . ($products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->display_price($products[$i]['onetime_charges'], zen_get_tax_rate($products[$i]['tax_class_id']), 1) : ''); $productsPriceEach = $currencies->display_price($products[$i]['final_price'], zen_get_tax_rate($products[$i]['tax_class_id']), 1) . ($products[$i]['onetime_charges'] != 0 ? '<br />' . $currencies->display_price($products[$i]['onetime_charges'], zen_get_tax_rate($products[$i]['tax_class_id']), 1) : ''); $productArray[$i] = array('attributeHiddenField' => $attributeHiddenField, 'flagStockCheck' => $flagStockCheck, 'model' => $productsName, 'flagShowFixedQuantity' => $showFixedQuantity, 'linkProductsImage' => $linkProductsImage, 'linkProductsName' => $linkProductsName, 'productsImage' => $productsImage, 'productsName' => $productsName, 'showFixedQuantity' => $showFixedQuantity, 'showFixedQuantityAmount' => $showFixedQuantityAmount, 'showMinUnits' => $showMinUnits, 'quantityField' => $quantityField, 'buttonUpdate' => $buttonUpdate, 'productsPrice' => $productsPrice, 'productsPriceEach' => $productsPriceEach, 'rowClass' => $rowClass, 'buttonDelete' => $buttonDelete, 'checkBoxDelete' => $checkBoxDelete, 'id' => $products[$i]['id'], 'attributes' => $attrArray);
function get_product_price($product_id) { global $db, $order; $products_id = zen_get_prid($product_id); // products price $qty = $_SESSION['cart']->contents[$product_id]['qty']; $product = $db->Execute("select products_id, products_price, products_tax_class_id, products_weight\n from " . TABLE_PRODUCTS . " where products_id='" . $products_id . "'"); if ($product->RecordCount() > 0) { $prid = $product->fields['products_id']; $products_tax = zen_get_tax_rate($product->fields['products_tax_class_id']); $products_price = $product->fields['products_price']; $specials = $db->Execute("select specials_new_products_price\n from " . TABLE_SPECIALS . " where products_id = '" . $prid . "' and status = '1'"); if ($specials->RecordCount() > 0) { $products_price = $specials->fields['specials_new_products_price']; } if ($this->include_tax == 'true') { $total_price += ($products_price + zen_calculate_tax($products_price, $products_tax)) * $qty; } else { $total_price += $products_price * $qty; } // attributes price if (isset($_SESSION['cart']->contents[$product_id]['attributes'])) { reset($_SESSION['cart']->contents[$product_id]['attributes']); while (list($option, $value) = each($_SESSION['cart']->contents[$product_id]['attributes'])) { $attribute_price = $db->Execute("select options_values_price, price_prefix\n from " . TABLE_PRODUCTS_ATTRIBUTES . "\n where products_id = '" . $prid . "'\n and options_id = '" . $option . "'\n and options_values_id = '" . $value . "'"); if ($attribute_price->fields['price_prefix'] == '-') { if ($this->include_tax == 'true') { $total_price -= $qty * ($attribute_price->fields['options_values_price'] + zen_calculate_tax($attribute_price->fields['options_values_price'], $products_tax)); } else { $total_price -= $qty * $attribute_price->fields['options_values_price']; } } else { if ($this->include_tax == 'true') { $total_price += $qty * ($attribute_price->fields['options_values_price'] + zen_calculate_tax($attribute_price->fields['options_values_price'], $products_tax)); } else { $total_price += $qty * $attribute_price->fields['options_values_price']; } } } } } return $total_price; }
} else { if ($wrap_mod->exclude_category($prid)) { echo GIFT_WRAP_NA; } else { $gift_id = "wrap_prod_" . $prod_count; if (isset($_SESSION[$gift_id]) && $_SESSION[$gift_id] != '') { $giftChecked = true; } else { $giftChecked = false; } echo zen_draw_checkbox_field($gift_id, '', $giftChecked, 'id="' . $gift_id . '" onclick="updateForm();"'); } } } } echo "<label><span class='fec-gift-price'><strong>" . $currencies->format($products_wrap_fee[zen_get_prid($order->products[$i]['id'])]) . "</strong></span>" . $order->products[$i]['name']; // if there are attributes, loop thru them and display one per line if (isset($order->products[$i]['attributes']) && sizeof($order->products[$i]['attributes']) > 0) { echo '<ul class="cartAttribsList">'; for ($j = 0, $n2 = sizeof($order->products[$i]['attributes']); $j < $n2; $j++) { echo '<li>' . $order->products[$i]['attributes'][$j]['option'] . ': ' . nl2br($order->products[$i]['attributes'][$j]['value']) . '</li>'; } // end loop echo '</ul>'; } // endif attribute-info echo "</label>"; echo "</div>"; ?> <?php $prod_count++;
/** * Method to calculate the number of items in a cart based on an abitrary property * * $check_what is the fieldname example: 'products_is_free' * $check_value is the value being tested for - default is 1 * Syntax: $this->getSessionVar('cart')->in_cart_check('product_is_free','1'); * * @param string product field to check * @param mixed value to check for * @return integer number of items matching restraint */ public function in_cart_check($check_what, $check_value = '1') { if (!is_array($this->contents)) { return 0; } // compute total quantity for field $in_cart_check_qty = 0; reset($this->contents); while (list($products_id, ) = each($this->contents)) { $testing_id = zen_get_prid($products_id); // check if field it true $product_check = $this->getDb()->Execute("select " . $check_what . " as check_it from %table.products% where products_id='" . $testing_id . "' limit 1"); if ($product_check->fields['check_it'] == $check_value) { $in_cart_check_qty += $this->contents[$products_id]['qty']; } } return $in_cart_check_qty; }
function zen_product_is_sba($product_id) { global $db; if (!isset($product_id) && !is_numeric(zen_get_prid($product_id))) { return null; } $inSBA_query = 'SELECT * FROM information_schema.tables WHERE table_schema = :your_db: AND table_name = :table_name: LIMIT 1;'; $inSBA_query = $db->bindVars($inSBA_query, ':your_db:', DB_DATABASE, 'string'); $inSBA_query = $db->bindVars($inSBA_query, ':table_name:', TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK, 'string'); $SBA_installed = $db->Execute($inSBA_query, false, false, 0, true); if (!$SBA_installed->EOF && $SBA_installed->RecordCount() > 0) { $isSBA_query = 'SELECT stock_id FROM ' . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . ' where products_id = :products_id:;'; $isSBA_query = $db->bindVars($isSBA_query, ':products_id:', $product_id, 'integer'); $isSBA = $db->Execute($isSBA_query); if (!$isSBA->EOF && $isSBA->RecordCount() > 0) { return true; } else { return false; } } return false; }
if ($show_shopping_cart_box == true) { if ($gBitCustomer->mCart->count_contents() > 0) { $id = 'shoppingcart'; $content = ""; if ($gBitCustomer->mCart->count_contents() > 0) { $content = '<table border="0" width="100%" cellspacing="0" cellpadding="0">'; foreach (array_keys($gBitCustomer->mCart->contents) as $productKey) { $product = $gBitCustomer->mCart->getProductObject($productKey); $productId = zen_get_prid($productKey); $content .= '<tr><td align="right" valign="top" class="infoboxcontents">'; if (!empty($_SESSION['new_products_id_in_cart']) && $_SESSION['new_products_id_in_cart'] == $productId) { $content .= '<span class="newItemInCart">'; } else { $content .= '<span class="infoboxcontents">'; } $content .= $gBitCustomer->mCart->contents[$productKey]['products_quantity'] . ' x </span></td><td valign="top" class="infoboxcontents"><a href="' . CommerceProduct::getDisplayUrlFromId(zen_get_prid($productId)) . '">'; if (!empty($_SESSION['new_products_id_in_cart']) && $_SESSION['new_products_id_in_cart'] == $productId) { $content .= '<span class="newItemInCart">'; } else { $content .= '<span class="infoboxcontents">'; } $content .= $product->getTitle() . '</span></a></td></tr>'; if (!empty($_SESSION['new_products_id_in_cart']) && $_SESSION['new_products_id_in_cart'] == $productId) { $_SESSION['new_products_id_in_cart'] = ''; } } $content .= '</table>'; if ($gvBalance = CommerceVoucher::getGiftAmount()) { $content .= '<table style="margin-top:10px;" cellpadding="0" width="100%" cellspacing="0" border="0"><tr><td class="smalltext">' . tra('Gift Certificate Balance') . '</td><td class="smalltext" align="right" valign="bottom">' . $gvBalance . '</td></tr></table>'; $content .= '<table cellpadding="0" width="100%" cellspacing="0" border="0"><tr><td class="smalltext"><a href="' . zen_href_link(FILENAME_GV_SEND) . '">' . tra('Send Gift Certificate') . '</a></td></tr></table>'; }
/** * Get wrap fee for products * @param $products_id * @return wrap_fee array */ function get_products_wrap_fee() { global $order; $products_wrap_fee = array(); // Compute wrap fee by seeing which ones are wrapped $wrapfee = 0; $items_wrapped = 0; for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) { $prid = $order->products[$i]['id']; for ($q = 1; $q <= $order->products[$i]['qty']; $q++) { //$wrapfee += ($this->itemfee + $this->apply_category_wrap_surcharge($prid) + $this->apply_product_wrap_surcharge($prid) ); $products_wrap_fee[zen_get_prid($prid)] = $this->itemfee + $this->apply_category_wrap_surcharge($prid) + $this->apply_product_wrap_surcharge($prid); $items_wrapped++; } } return $products_wrap_fee; }
function _build_attributes_combinations($attributes, $showoos, $markoos, &$combinations, &$selected_combination, $oidindex = 0, $comb = array(), $id = "", $text = '', $isselected = true) { global $cart; foreach ($attributes[$oidindex]['ovals'] as $attrib) { $newcomb = $comb; $newcomb[$attributes[$oidindex]['oid']] = $attrib['id']; $newid = $id . ',' . $attributes[$oidindex]['oid'] . '-' . $attrib['id']; $newtext = $text . ", " . $attrib['text']; if (isset($cart->contents[$this->products_id]['attributes'][$attributes[$oidindex]['oid']])) { $newisselected = $cart->contents[$this->products_id]['attributes'][$attributes[$oidindex]['oid']] == $attrib['id'] ? $isselected : false; } else { $newisselected = false; } if (isset($attributes[$oidindex + 1])) { $this->_build_attributes_combinations($attributes, $showoos, $markoos, $combinations, $selected_combination, $oidindex + 1, $newcomb, $newid, $newtext, $newisselected); } else { $is_out_of_stock = zen_check_stock(zen_get_prid($this->products_id), 1, $newcomb); if (!$is_out_of_stock | $showoos == true) { switch ($markoos) { case 'Left': $newtext = ($is_out_of_stock ? TEXT_OUT_OF_STOCK . ' - ' : '') . substr($newtext, 2); break; case 'Right': $newtext = substr($newtext, 2) . ($is_out_of_stock ? ' - ' . TEXT_OUT_OF_STOCK : ''); break; default: $newtext = substr($newtext, 2); break; } $combinations[] = array('comb' => $newcomb, 'id' => substr($newid, 1), 'text' => $newtext); if ($newisselected) { $selected_combination = sizeof($combinations) - 1; } } // EOF if !$is_out_of_stock etc... } // EOF Else } // EOF foreach }
function zen_get_products_price_is_priced_by_attributes($products_id) { global $gBitDb; $product_check = $gBitDb->getOne("select `products_priced_by_attribute` from " . TABLE_PRODUCTS . " where `products_id` = ?", array(zen_get_prid($products_id))); return $product_check == '1'; }
function create_add_products($zf_insert_id, $zf_mode = false) { global $db, $currencies, $order_total_modules, $order_totals; // initialized for the email confirmation $this->products_ordered = ''; $this->products_ordered_html = ''; $this->subtotal = 0; $this->total_tax = 0; // lowstock email report $this->email_low_stock = ''; for ($i = 0, $n = sizeof($this->products); $i < $n; $i++) { $custom_insertable_text = ''; $this->doStockDecrement = STOCK_LIMITED == 'true'; $this->notify('NOTIFY_ORDER_PROCESSING_STOCK_DECREMENT_INIT', array('i' => $i), $this->products[$i], $i); // Stock Update - Joao Correia if ($this->doStockDecrement) { if (DOWNLOAD_ENABLED == 'true') { $stock_query_raw = "select p.products_quantity, pad.products_attributes_filename, p.product_is_always_free_shipping\n from " . TABLE_PRODUCTS . " p\n left join " . TABLE_PRODUCTS_ATTRIBUTES . " pa\n on p.products_id=pa.products_id\n left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad\n on pa.products_attributes_id=pad.products_attributes_id\n WHERE p.products_id = '" . zen_get_prid($this->products[$i]['id']) . "'"; // Will work with only one option for downloadable products // otherwise, we have to build the query dynamically with a loop $products_attributes = $this->products[$i]['attributes']; if (is_array($products_attributes)) { $stock_query_raw .= " AND pa.options_id = '" . $products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . $products_attributes[0]['value_id'] . "'"; } $stock_values = $db->Execute($stock_query_raw, false, false, 0, true); } else { $stock_values = $db->Execute("select * from " . TABLE_PRODUCTS . " where products_id = '" . zen_get_prid($this->products[$i]['id']) . "'", false, false, 0, true); } $this->notify('NOTIFY_ORDER_PROCESSING_STOCK_DECREMENT_BEGIN', $i, $stock_values); if ($stock_values->RecordCount() > 0) { // do not decrement quantities if products_attributes_filename exists if (DOWNLOAD_ENABLED != 'true' || $stock_values->fields['product_is_always_free_shipping'] == 2 || !$stock_values->fields['products_attributes_filename']) { $stock_left = $stock_values->fields['products_quantity'] - $this->products[$i]['qty']; $this->products[$i]['stock_reduce'] = $this->products[$i]['qty']; } else { $stock_left = $stock_values->fields['products_quantity']; } // $this->products[$i]['stock_value'] = $stock_values->fields['products_quantity']; $db->Execute("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . zen_get_prid($this->products[$i]['id']) . "'"); // if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT == 'false') ) { if ($stock_left <= 0) { // only set status to off when not displaying sold out if (SHOW_PRODUCTS_SOLD_OUT == '0') { $db->Execute("update " . TABLE_PRODUCTS . " set products_status = 0 where products_id = '" . zen_get_prid($this->products[$i]['id']) . "'"); } } // for low stock email if ($stock_left <= STOCK_REORDER_LEVEL) { // WebMakers.com Added: add to low stock email $this->email_low_stock .= 'ID# ' . zen_get_prid($this->products[$i]['id']) . "\t\t" . $this->products[$i]['model'] . "\t\t" . $this->products[$i]['name'] . "\t\t" . ' Qty Left: ' . $stock_left . "\n"; } } } // Update products_ordered (for bestsellers list) $this->bestSellersUpdate = TRUE; $this->notify('NOTIFY_ORDER_PROCESSING_BESTSELLERS_UPDATE', array(), $this->products[$i], $i); if ($this->bestSellersUpdate) { $db->Execute("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%f', $this->products[$i]['qty']) . " where products_id = '" . zen_get_prid($this->products[$i]['id']) . "'"); } $this->notify('NOTIFY_ORDER_PROCESSING_STOCK_DECREMENT_END', $i); $sql_data_array = array('orders_id' => $zf_insert_id, 'products_id' => zen_get_prid($this->products[$i]['id']), 'products_model' => $this->products[$i]['model'], 'products_name' => $this->products[$i]['name'], 'products_price' => $this->products[$i]['price'], 'final_price' => $this->products[$i]['final_price'], 'onetime_charges' => $this->products[$i]['onetime_charges'], 'products_tax' => $this->products[$i]['tax'], 'products_quantity' => $this->products[$i]['qty'], 'products_priced_by_attribute' => $this->products[$i]['products_priced_by_attribute'], 'product_is_free' => $this->products[$i]['product_is_free'], 'products_discount_type' => $this->products[$i]['products_discount_type'], 'products_discount_type_from' => $this->products[$i]['products_discount_type_from'], 'products_prid' => $this->products[$i]['id']); zen_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array); $order_products_id = $db->Insert_ID(); $this->notify('NOTIFY_ORDER_DURING_CREATE_ADDED_PRODUCT_LINE_ITEM', array_merge(array('orders_products_id' => $order_products_id, 'i' => $i), $sql_data_array), $order_products_id); $this->notify('NOTIFY_ORDER_PROCESSING_CREDIT_ACCOUNT_UPDATE_BEGIN'); $order_total_modules->update_credit_account($i); //ICW ADDED FOR CREDIT CLASS SYSTEM $this->notify('NOTIFY_ORDER_PROCESSING_ATTRIBUTES_BEGIN'); //------ bof: insert customer-chosen options to order-------- $attributes_exist = '0'; $this->products_ordered_attributes = ''; if (isset($this->products[$i]['attributes'])) { $attributes_exist = '1'; for ($j = 0, $n2 = sizeof($this->products[$i]['attributes']); $j < $n2; $j++) { if (DOWNLOAD_ENABLED == 'true') { $attributes_query = "select popt.products_options_name, poval.products_options_values_name,\n pa.options_values_price, pa.price_prefix,\n pa.product_attribute_is_free, pa.products_attributes_weight, pa.products_attributes_weight_prefix,\n pa.attributes_discounted, pa.attributes_price_base_included, pa.attributes_price_onetime,\n pa.attributes_price_factor, pa.attributes_price_factor_offset,\n pa.attributes_price_factor_onetime, pa.attributes_price_factor_onetime_offset,\n pa.attributes_qty_prices, pa.attributes_qty_prices_onetime,\n pa.attributes_price_words, pa.attributes_price_words_free,\n pa.attributes_price_letters, pa.attributes_price_letters_free,\n pad.products_attributes_maxdays, pad.products_attributes_maxcount, pad.products_attributes_filename\n from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa\n left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad\n on pa.products_attributes_id=pad.products_attributes_id\n where pa.products_id = '" . zen_db_input($this->products[$i]['id']) . "'\n and pa.options_id = '" . $this->products[$i]['attributes'][$j]['option_id'] . "'\n and pa.options_id = popt.products_options_id\n and pa.options_values_id = '" . $this->products[$i]['attributes'][$j]['value_id'] . "'\n and pa.options_values_id = poval.products_options_values_id\n and popt.language_id = '" . $_SESSION['languages_id'] . "'\n and poval.language_id = '" . $_SESSION['languages_id'] . "'"; $attributes_values = $db->Execute($attributes_query); } else { $attributes_values = $db->Execute("select popt.products_options_name, poval.products_options_values_name,\n pa.options_values_price, pa.price_prefix,\n pa.product_attribute_is_free, pa.products_attributes_weight, pa.products_attributes_weight_prefix,\n pa.attributes_discounted, pa.attributes_price_base_included, pa.attributes_price_onetime,\n pa.attributes_price_factor, pa.attributes_price_factor_offset,\n pa.attributes_price_factor_onetime, pa.attributes_price_factor_onetime_offset,\n pa.attributes_qty_prices, pa.attributes_qty_prices_onetime,\n pa.attributes_price_words, pa.attributes_price_words_free,\n pa.attributes_price_letters, pa.attributes_price_letters_free\n from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa\n where pa.products_id = '" . $this->products[$i]['id'] . "' and pa.options_id = '" . (int) $this->products[$i]['attributes'][$j]['option_id'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . (int) $this->products[$i]['attributes'][$j]['value_id'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $_SESSION['languages_id'] . "' and poval.language_id = '" . $_SESSION['languages_id'] . "'"); } //clr 030714 update insert query. changing to use values form $order->products for products_options_values. $sql_data_array = array('orders_id' => $zf_insert_id, 'orders_products_id' => $order_products_id, 'products_options' => $attributes_values->fields['products_options_name'], 'products_options_values' => $this->products[$i]['attributes'][$j]['value'], 'options_values_price' => $attributes_values->fields['options_values_price'], 'price_prefix' => $attributes_values->fields['price_prefix'], 'product_attribute_is_free' => $attributes_values->fields['product_attribute_is_free'], 'products_attributes_weight' => $attributes_values->fields['products_attributes_weight'], 'products_attributes_weight_prefix' => $attributes_values->fields['products_attributes_weight_prefix'], 'attributes_discounted' => $attributes_values->fields['attributes_discounted'], 'attributes_price_base_included' => $attributes_values->fields['attributes_price_base_included'], 'attributes_price_onetime' => $attributes_values->fields['attributes_price_onetime'], 'attributes_price_factor' => $attributes_values->fields['attributes_price_factor'], 'attributes_price_factor_offset' => $attributes_values->fields['attributes_price_factor_offset'], 'attributes_price_factor_onetime' => $attributes_values->fields['attributes_price_factor_onetime'], 'attributes_price_factor_onetime_offset' => $attributes_values->fields['attributes_price_factor_onetime_offset'], 'attributes_qty_prices' => $attributes_values->fields['attributes_qty_prices'], 'attributes_qty_prices_onetime' => $attributes_values->fields['attributes_qty_prices_onetime'], 'attributes_price_words' => $attributes_values->fields['attributes_price_words'], 'attributes_price_words_free' => $attributes_values->fields['attributes_price_words_free'], 'attributes_price_letters' => $attributes_values->fields['attributes_price_letters'], 'attributes_price_letters_free' => $attributes_values->fields['attributes_price_letters_free'], 'products_options_id' => (int) $this->products[$i]['attributes'][$j]['option_id'], 'products_options_values_id' => (int) $this->products[$i]['attributes'][$j]['value_id'], 'products_prid' => $this->products[$i]['id']); zen_db_perform(TABLE_ORDERS_PRODUCTS_ATTRIBUTES, $sql_data_array); $opa_insert_id = $db->insert_ID(); $this->notify('NOTIFY_ORDER_DURING_CREATE_ADDED_ATTRIBUTE_LINE_ITEM', array_merge(array('orders_products_attributes_id' => $opa_insert_id), $sql_data_array), $opa_insert_id); if (DOWNLOAD_ENABLED == 'true' && isset($attributes_values->fields['products_attributes_filename']) && zen_not_null($attributes_values->fields['products_attributes_filename'])) { $sql_data_array = array('orders_id' => $zf_insert_id, 'orders_products_id' => $order_products_id, 'orders_products_filename' => $attributes_values->fields['products_attributes_filename'], 'download_maxdays' => $attributes_values->fields['products_attributes_maxdays'], 'download_count' => $attributes_values->fields['products_attributes_maxcount'], 'products_prid' => $this->products[$i]['id']); zen_db_perform(TABLE_ORDERS_PRODUCTS_DOWNLOAD, $sql_data_array); $opd_insert_id = $db->insert_ID(); $this->notify('NOTIFY_ORDER_DURING_CREATE_ADDED_ATTRIBUTE_DOWNLOAD_LINE_ITEM', $sql_data_array, $opd_insert_id); } $this->products_ordered_attributes .= "\n\t" . $attributes_values->fields['products_options_name'] . ' ' . zen_decode_specialchars($this->products[$i]['attributes'][$j]['value']); } } //------eof: insert customer-chosen options ---- $this->notify('NOTIFY_ORDER_PROCESSING_ATTRIBUTES_EXIST', $attributes_exist); $this->notify('NOTIFY_ORDER_DURING_CREATE_ADD_PRODUCTS', $i, $custom_insertable_text); /* START: ADD MY CUSTOM DETAILS * 1. calculate/prepare custom information to be added to this product entry in order-confirmation, perhaps as a function call to custom code to build a serial number etc: * Possible parameters to pass to custom functions at this point: * Product ID ordered (for this line item): $this->products[$i]['id'] * Quantity ordered (of this line-item): $this->products[$i]['qty'] * Order number: $zf_insert_id * Attribute Option Name ID: (int)$this->products[$i]['attributes'][$j]['option_id'] * Attribute Option Value ID: (int)$this->products[$i]['attributes'][$j]['value_id'] * Attribute Filename: $attributes_values->fields['products_attributes_filename'] * * 2. Add that data to the $this->products_ordered_attributes variable, using this sort of format: * $this->products_ordered_attributes .= {INSERT CUSTOM INFORMATION HERE}; */ $this->products_ordered_attributes .= $custom_insertable_text; /* END: ADD MY CUSTOM DETAILS */ // update totals counters $this->total_weight += $this->products[$i]['qty'] * $this->products[$i]['weight']; $this->total_tax += zen_calculate_tax($this->products[$i]['final_price'] * $this->products[$i]['qty'], $this->products[$i]['tax']); $this->total_cost += $this->products[$i]['final_price'] + $this->products[$i]['onetime_charges']; $this->notify('NOTIFY_ORDER_PROCESSING_ONE_TIME_CHARGES_BEGIN', $i); // build output for email notification $this->products_ordered .= $this->products[$i]['qty'] . ' x ' . $this->products[$i]['name'] . ($this->products[$i]['model'] != '' ? ' (' . $this->products[$i]['model'] . ') ' : '') . ' = ' . $currencies->display_price($this->products[$i]['final_price'], $this->products[$i]['tax'], $this->products[$i]['qty']) . ($this->products[$i]['onetime_charges'] != 0 ? "\n" . TEXT_ONETIME_CHARGES_EMAIL . $currencies->display_price($this->products[$i]['onetime_charges'], $this->products[$i]['tax'], 1) : '') . $this->products_ordered_attributes . "\n"; $this->products_ordered_html .= '<tr>' . "\n" . '<td class="product-details" align="right" valign="top" width="30">' . $this->products[$i]['qty'] . ' x</td>' . "\n" . '<td class="product-details" valign="top">' . nl2br($this->products[$i]['name']) . ($this->products[$i]['model'] != '' ? ' (' . nl2br($this->products[$i]['model']) . ') ' : '') . "\n" . '<nobr>' . '<small><em> ' . nl2br($this->products_ordered_attributes) . '</em></small>' . '</nobr>' . '</td>' . "\n" . '<td class="product-details-num" valign="top" align="right">' . $currencies->display_price($this->products[$i]['final_price'], $this->products[$i]['tax'], $this->products[$i]['qty']) . ($this->products[$i]['onetime_charges'] != 0 ? '</td></tr>' . "\n" . '<tr><td class="product-details">' . nl2br(TEXT_ONETIME_CHARGES_EMAIL) . '</td>' . "\n" . '<td>' . $currencies->display_price($this->products[$i]['onetime_charges'], $this->products[$i]['tax'], 1) : '') . '</td></tr>' . "\n"; } $order_total_modules->apply_credit(); //ICW ADDED FOR CREDIT CLASS SYSTEM $this->notify('NOTIFY_ORDER_AFTER_ORDER_CREATE_ADD_PRODUCTS'); }
default: $ga_order = $order->customer; break; } // get total tax shipping $ga_order['total'] = number_format(zen_round($order->info['total'], $currencies[$order->info['currency']]['decimal_places']), $currencies[$order->info['currency']]['decimal_places'], $currencies[$order->info['currency']]['decimal_point'], ''); $ga_order['tax'] = number_format(zen_round($order->info['tax'], $currencies[$order->info['currency']]['decimal_places']), $currencies[$order->info['currency']]['decimal_places'], $currencies[$order->info['currency']]['decimal_point'], ''); $orders_total_query = "select value from " . TABLE_ORDERS_TOTAL . "\n where orders_id = :ordersid\n and class = 'ot_shipping'"; $orders_total_query = $db->bindvars($orders_total_query, ':ordersid', $orders_id, 'integer'); $orders_total = $db->execute($orders_total_query); $ga_order['shippingcost'] = number_format(zen_round($orders_total->fields['value'], $currencies[$order->info['currency']]['decimal_places']), $currencies[$order->info['currency']]['decimal_places'], $currencies[$order->info['currency']]['decimal_point'], ''); $ga_order['affiliation'] = MODULE_GOOGLE_ANALYTICS_AFFILIATION; // get products data $ga_products = array(); for ($i = 0; $i < sizeof($order->products); $i++) { $ga_products[$i]['categories_name'] = zen_get_categories_name_from_product(zen_get_prid($order->products[$i]['id'])); if (MODULE_GOOGLE_ANALYTICS_SKU_OR_CODE == 'products_model') { $ga_products[$i]['skucode'] = $order->products[$i]['model']; } else { $ga_products[$i]['skucode'] = $order->products[$i]['id']; } $ga_products[$i]['final_price'] = number_format(zen_round($order->products[$i]['final_price'], $currencies[$order->info['currency']]['decimal_places']), $currencies[$order->info['currency']]['decimal_places'], $currencies[$order->info['currency']]['decimal_point'], ''); $ga_products[$i]['qty'] = $order->products[$i]['qty']; // get product name and attributes_name $ga_products[$i]['name'] = $order->products[$i]['name']; if (isset($order->products[$i]['attributes'])) { $products_attributes = array(); for ($j = 0; $j < sizeof($order->products[$i]['attributes']); $j++) { $products_attributes[$j] = $order->products[$i]['attributes'][$j]['option'] . ': ' . $order->products[$i]['attributes'][$j]['value']; } $attributes = substr(MODULE_GOOGLE_ANALYTICS_BRACKETS, 0, 1) . implode(MODULE_GOOGLE_ANALYTICS_DELIMITER, $products_attributes) . substr(MODULE_GOOGLE_ANALYTICS_BRACKETS, -1, 1);