예제 #1
0
 /**
  * Получить стоимость товара $elementId (со скидкой и без одновременно)
  * @param Integer $elementId
  * @param String $template = 'default'
  * @param Boolean $showAllCurrency = false
  * @return Mixed
  */
 public function price($elementId = null, $template = 'default', $showAllCurrency = true)
 {
     if (!$elementId) {
         return;
     }
     $hierarchy = umiHierarchy::getInstance();
     $elementId = $this->analyzeRequiredPath($elementId);
     if ($elementId == false) {
         throw new publicException("Wrong element id given");
     }
     $element = $hierarchy->getElement($elementId);
     if ($element instanceof iUmiHierarchyElement == false) {
         throw new publicException("Wrong element id given");
     }
     list($tpl_block) = def_module::loadTemplates("emarket/" . $template, 'price_block');
     $originalPrice = $element->price;
     //Discounts
     $result = array('attribute:element-id' => $elementId);
     $discount = itemDiscount::search($element);
     if ($discount instanceof discount) {
         $result['discount'] = array('attribute:id' => $discount->id, 'attribute:name' => $discount->getName(), 'description' => $discount->getValue('description'));
         $result['void:discount_id'] = $discount->id;
     }
     //Currency
     $price = self::formatPrice($element->price, $discount);
     if ($currencyPrice = $this->formatCurrencyPrice($price)) {
         $result['price'] = $currencyPrice;
     } else {
         $result['price'] = $price;
     }
     $result['price'] = $this->parsePriceTpl($template, $result['price']);
     $result['void:price-original'] = getArrayKey($result['price'], 'original');
     $result['void:price-actual'] = getArrayKey($result['price'], 'actual');
     if ($showAllCurrency) {
         $result['currencies'] = $this->formatCurrencyPrices($price);
         $result['currency-prices'] = $this->parseCurrencyPricesTpl($template, $price);
     }
     return def_module::parseTemplate($tpl_block, $result);
 }
예제 #2
0
 /**
  * Найти скидку, применимую к этому наименованию в заказе
  */
 protected function searchDiscount()
 {
     $element = $this->getItemElement();
     if ($element instanceof iUmiHierarchyElement) {
         $discount = itemDiscount::search($element);
         if ($discount instanceof discount) {
             return $discount;
         }
     }
     return null;
 }