/** * Returns the shipment arrays (shippers and shipment costs) in JavaScript * syntax. * * Backend use only. * @static * @return string The Shipment arrays definition */ static function getJSArrays() { if (is_null(self::$arrShipments)) { self::init(true); } // Set up shipment cost javascript arrays // Shippers are not needed for calculating the shipment costs //$strJsArrays = "arrShippers = new Array();\narrShipments = new Array();\n"; $strJsArrays = "arrShipments = new Array();\n"; // Insert shippers by id foreach (array_keys(self::$arrShippers) as $shipper_id) { //$strJsArrays .= "arrShippers[$shipper_id] = new Array('". // self::$arrShippers[$shipper_id]['name']."', ". // self::$arrShippers[$shipper_id]['status'].");\n"; // Insert shipments by shipper id $strJsArrays .= "arrShipments[{$shipper_id}] = new Array();\n"; $i = 0; if (isset(self::$arrShipments[$shipper_id])) { foreach (self::$arrShipments[$shipper_id] as $shipment_id => $arrShipment) { $strJsArrays .= "arrShipments[{$shipper_id}][" . $i++ . "] = new Array('{$shipment_id}', '" . $arrShipment['max_weight'] . "', '" . Currency::getCurrencyPrice($arrShipment['free_from']) . "', '" . Currency::getCurrencyPrice($arrShipment['fee']) . "');\n"; } } } return $strJsArrays; }
/** * Returns the actual payment fee according to the payment ID and * the total order price. * * @internal A lot of this belongs to the Payment class. * @param integer $payment_id The payment ID * @param double $totalPrice The total order price * @return string The payment fee, formatted by * {@link Currency::getCurrencyPrice()} */ static function _calculatePaymentPrice($payment_id, $totalPrice) { $paymentPrice = 0; if (!$payment_id) { return $paymentPrice; } if (Payment::getProperty($payment_id, 'free_from') == 0 || $totalPrice < Payment::getProperty($payment_id, 'free_from')) { $paymentPrice = Payment::getProperty($payment_id, 'fee'); } return Currency::getCurrencyPrice($paymentPrice); }
/** * Returns a product price in the active currency, depending on the * Customer and special offer status. * @param Customer $objCustomer The Customer, or null * @param double $price_options The price for Attributes, * if any, or 0 (zero) * @param integer $count The number of products, defaults * to 1 (one) * @param boolean $ignore_special_offer * If true, special offers are ignored. * This is needed to actually determine * both prices in the products view. * Defaults to false. * @return double The price converted to the active * currency * @author Reto Kohli <*****@*****.**> */ function get_custom_price($objCustomer = null, $price_options = 0, $count = 1, $ignore_special_offer = false) { $normalPrice = $this->price(); $resellerPrice = $this->resellerprice(); $discountPrice = $this->discountprice(); $discount_active = $this->discount_active(); $groupCountId = $this->group_id(); $groupArticleId = $this->article_id(); $price = $normalPrice; if (!$ignore_special_offer && $discount_active == 1 && $discountPrice != 0) { $price = $discountPrice; } else { if ($objCustomer && $objCustomer->is_reseller() && $resellerPrice != 0) { $price = $resellerPrice; } } $price += $price_options; $rateCustomer = 0; if ($objCustomer) { $groupCustomerId = $objCustomer->group_id(); if ($groupCustomerId) { $rateCustomer = Discount::getDiscountRateCustomer($groupCustomerId, $groupArticleId); $price -= $price * $rateCustomer * 0.01; } } $rateCount = 0; if ($count > 0) { $rateCount = Discount::getDiscountRateCount($groupCountId, $count); $price -= $price * $rateCount * 0.01; } $price = Currency::getCurrencyPrice($price); return $price; }
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; }