예제 #1
0
 protected static function getProductProfit($productInfo)
 {
     if (strlen($productInfo['GROSS_PROFIT']) > 0) {
         $profit = doubleval($productInfo['GROSS_PROFIT']);
     } else {
         $purchasingCost = 0;
         if (strlen($productInfo['SUMMARY_PURCHASING_PRICE']) > 0) {
             $purchasingCost = doubleval($productInfo['SUMMARY_PURCHASING_PRICE']);
         } else {
             $dbRes = ProductTable::getList(array('filter' => array('=ID' => $productInfo['PRODUCT_ID']), 'select' => array('ID', 'PURCHASING_PRICE', 'PURCHASING_CURRENCY')));
             $productInfoBase = $dbRes->fetch();
             if ($productInfoBase) {
                 $purchasingCost = $productInfoBase['PURCHASING_PRICE'] * $productInfo['QUANTITY'];
                 $baseCurrency = CurrencyManager::getBaseCurrency();
                 if ($baseCurrency != $productInfoBase['PURCHASING_CURRENCY']) {
                     $purchasingCost = \CCurrencyRates::convertCurrency($purchasingCost, $productInfoBase['PURCHASING_CURRENCY'], $baseCurrency);
                 }
             }
         }
         $profit = doubleval($productInfo['SUMMARY_PRICE']) - $purchasingCost;
     }
     return $profit;
 }
예제 #2
0
 /**
  * Получает информацию о товаре из Битрикса
  */
 public function loadItemInfo()
 {
     if (!$this->id) {
         return;
     }
     $elementManager = new \CIBlockElement();
     if ($info = $elementManager->GetByID($this->id)->GetNext(true, false)) {
         $this->setName($info['NAME']);
         $this->setPreviewPicture($info['PREVIEW_PICTURE']);
         $this->setDetailPicture($info['DETAIL_PICTURE']);
         $this->setUrl($info['DETAIL_PAGE_URL']);
     }
     if (Loader::includeModule('sale')) {
         $priceManager = new \CPrice();
         $price = $priceManager->GetBasePrice($this->id);
         $this->setPrice($price['PRICE']);
     }
     if (Loader::includeModule('catalog') && !$this->quantity) {
         $parameters = ['filter' => ['ID' => $this->id], 'select' => ['ID', 'QUANTITY']];
         $storeDb = ProductTable::getList($parameters);
         while ($arData = $storeDb->fetch()) {
             $this->quantity += (int) $arData['QUANTITY'];
         }
     }
     if ($this->quantity < 0) {
         $this->quantity = 0;
     }
 }