static function getJavascriptArray($groupCustomerId = 0, $isReseller = false) { global $objDatabase; // create javascript array containing all products; // used to update the display when changing the product ID. // we need the VAT rate in there as well in order to be able to correctly change the products, // and the flag indicating whether the VAT is included in the prices already. $strJsArrProduct = 'var vat_included = ' . intval(Vat::isIncluded()) . ";\nvar arrProducts = new Array();\n"; $arrSql = \Text::getSqlSnippets('`product`.`id`', FRONTEND_LANG_ID, 'Shop', array('name' => Product::TEXT_NAME, 'code' => Product::TEXT_CODE)); $query = "\n SELECT `product`.`id`,\n `product`.`resellerprice`, `product`.`normalprice`,\n `product`.`discountprice`, `product`.`discount_active`,\n `product`.`weight`, `product`.`vat_id`,\n `product`.`distribution`,\n `product`.`group_id`, `product`.`article_id`, " . $arrSql['field'] . "\n FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_products` AS `product`" . $arrSql['join'] . "\n WHERE `product`.`active`=1"; $objResult = $objDatabase->Execute($query); if (!$objResult) { return Product::errorHandler(); } while (!$objResult->EOF) { $id = $objResult->fields['id']; $distribution = $objResult->fields['distribution']; $strCode = $objResult->fields['code']; if ($strCode === null) { $strCode = \Text::getById($id, 'Shop', Product::TEXT_CODE)->content(); } $strName = $objResult->fields['name']; if ($strName === null) { $strName = \Text::getById($id, 'Shop', Product::TEXT_NAME)->content(); } $price = $objResult->fields['normalprice']; if ($objResult->fields['discount_active']) { $price = $objResult->fields['discountprice']; } elseif ($isReseller) { $price = $objResult->fields['resellerprice']; } // Determine discounted price from customer and article group matrix $discountCustomerRate = Discount::getDiscountRateCustomer($groupCustomerId, $objResult->fields['article_id']); $price -= $price * $discountCustomerRate * 0.01; // Determine prices for various count discounts, if any $arrDiscountCountRate = Discount::getDiscountCountRateArray($objResult->fields['group_id']); //\DBG::log("Products::getJavascriptArray($groupCustomerId, $isReseller): Discount rate array: ".var_export($arrDiscountCountRate, true)); // Order the counts in reverse, from highest to lowest $strJsArrPrice = ''; if (is_array($arrDiscountCountRate)) { foreach ($arrDiscountCountRate as $count => $rate) { // Deduct the customer type discount right away //\DBG::log("Products::getJavascriptArray(): price $price, rate $rate"); $discountPrice = $price - $price * $rate * 0.01; $strJsArrPrice .= ($strJsArrPrice ? ',' : '') . $count . ',' . Currency::getCurrencyPrice($discountPrice); } } $strJsArrPrice .= ($strJsArrPrice ? ',' : '') . '0,' . Currency::getCurrencyPrice($price); $strJsArrProduct .= 'arrProducts[' . $id . '] = {' . 'id:' . $id . ',' . 'code:"' . $strCode . '",' . 'title:"' . htmlspecialchars($strName, ENT_QUOTES, CONTREXX_CHARSET) . '",' . 'percent:' . Vat::getRate($objResult->fields['vat_id']) . ',' . 'weight:' . ($distribution == 'delivery' ? '"' . Weight::getWeightString($objResult->fields['weight']) . '"' : '0') . ',' . 'price:[' . $strJsArrPrice . "]};\n"; $objResult->MoveNext(); } return $strJsArrProduct; }
/** * Returns a string representation of the count type discounts * applicable for the given discount group ID, if any. * @param integer $groupCountId The discount group ID * @return string The string representation * @global array $_ARRAYLANG Language array * @author Reto Kohli <*****@*****.**> * @static */ static function getDiscountCountString($groupCountId) { global $_ARRAYLANG; $arrDiscount = Discount::getDiscountCountArray(); $arrRate = Discount::getDiscountCountRateArray($groupCountId); $strDiscounts = ''; if (!empty($arrRate)) { $unit = ''; if (isset($arrDiscount[$groupCountId])) { $unit = $arrDiscount[$groupCountId]['unit']; } foreach ($arrRate as $count => $rate) { $strDiscounts .= ($strDiscounts != '' ? ', ' : '') . $_ARRAYLANG['TXT_SHOP_DISCOUNT_FROM'] . ' ' . $count . ' ' . $unit . $_ARRAYLANG['TXT_SHOP_DISCOUNT_TO'] . ' ' . $rate . '%'; } $strDiscounts = $_ARRAYLANG['TXT_SHOP_DISCOUNT_COUNT'] . ' ' . $strDiscounts; } return $strDiscounts; }
/** * Show the count discount editing page * @return boolean True on success, false otherwise * @author Reto Kohli <*****@*****.**> */ function view_discount_groups_count() { global $_ARRAYLANG; if (isset($_POST['discountStore'])) { $this->store_discount_count(); } if (isset($_GET['deleteDiscount'])) { $this->delete_discount_count(); } // Force discounts to be reinitialised Discount::flush(); self::$objTemplate->addBlockfile('SHOP_PRODUCTS_FILE', 'shop_products_block', 'module_shop_discount_groups_count.html'); // Discounts overview $arrDiscounts = Discount::getDiscountCountArray(); $i = 0; foreach ($arrDiscounts as $id => $arrDiscount) { $name = $arrDiscount['name']; $unit = $arrDiscount['unit']; self::$objTemplate->setVariable(array('SHOP_DISCOUNT_ID' => $id, 'SHOP_DISCOUNT_GROUP_NAME' => contrexx_raw2xhtml($name), 'SHOP_DISCOUNT_GROUP_UNIT' => contrexx_raw2xhtml($unit), 'SHOP_DISCOUNT_ROW_STYLE' => 'row' . (++$i % 2 + 1))); self::$objTemplate->parse('discount'); } // Add/edit Discount $id = 0; $arrDiscountRates = array(); if (!empty($_GET['editDiscount'])) { $id = intval($_GET['id']); $arrDiscountRates = Discount::getDiscountCountRateArray($id); self::$objTemplate->setGlobalVariable(array('SHOP_DISCOUNT_EDIT_CLASS' => 'active', 'SHOP_DISCOUNT_EDIT_DISPLAY' => 'block', 'SHOP_DISCOUNT_LIST_CLASS' => '', 'SHOP_DISCOUNT_LIST_DISPLAY' => 'none', 'TXT_ADD_OR_EDIT' => $_ARRAYLANG['TXT_EDIT'])); } else { self::$objTemplate->setGlobalVariable(array('SHOP_DISCOUNT_EDIT_CLASS' => '', 'SHOP_DISCOUNT_EDIT_DISPLAY' => 'none', 'SHOP_DISCOUNT_LIST_CLASS' => 'active', 'SHOP_DISCOUNT_LIST_DISPLAY' => 'block', 'TXT_ADD_OR_EDIT' => $_ARRAYLANG['TXT_ADD'])); } self::$objTemplate->setCurrentBlock('discountName'); self::$objTemplate->setVariable(array('SHOP_DISCOUNT_ID_EDIT' => $id, 'SHOP_DISCOUNT_ROW_STYLE' => 'row' . (++$i % 2 + 1))); if (isset($arrDiscounts[$id])) { $arrDiscount = $arrDiscounts[$id]; $name = $arrDiscount['name']; $unit = $arrDiscount['unit']; self::$objTemplate->setVariable(array('SHOP_DISCOUNT_GROUP_NAME' => $name, 'SHOP_DISCOUNT_GROUP_UNIT' => $unit)); } self::$objTemplate->parse('discountName'); self::$objTemplate->setCurrentBlock('discountRate'); if (isset($arrDiscountRates)) { $arrDiscountRates = array_reverse($arrDiscountRates, true); foreach ($arrDiscountRates as $count => $rate) { self::$objTemplate->setVariable(array('SHOP_DISCOUNT_COUNT' => $count, 'SHOP_DISCOUNT_RATE' => $rate, 'SHOP_DISCOUNT_RATE_INDEX' => $i, 'SHOP_DISCOUNT_ROW_STYLE' => 'row' . (++$i % 2 + 1))); self::$objTemplate->parse('discountRate'); } } // Add a few empty rows for adding new counts and rates for ($j = 0; $j < 5; ++$j) { self::$objTemplate->setVariable(array('SHOP_DISCOUNT_COUNT' => '', 'SHOP_DISCOUNT_RATE' => '', 'SHOP_DISCOUNT_RATE_INDEX' => $i, 'SHOP_DISCOUNT_ROW_STYLE' => 'row' . (++$i % 2 + 1))); self::$objTemplate->parse('discountRate'); } return true; }