Exemplo n.º 1
0
 /**
  * Function updates item prices its product data.
  *
  * @param ApiItemInterface $item
  * @param array $data
  */
 private function updatePrices(ApiItemInterface $item, $data)
 {
     $currency = null;
     // Set products price by data.
     if ($item->getUseProductsPrice() === false) {
         $item->setPrice($this->getProperty($data, 'price', $item->getPrice()));
     }
     // Set items total net price.
     $price = $this->itemPriceCalculator->calculateItemTotalNetPrice($item, $currency, $item->getUseProductsPrice());
     $item->setTotalNetPrice($price);
     // Set items price.
     $itemPrice = $this->itemPriceCalculator->calculateItemNetPrice($item, $currency, $item->getUseProductsPrice());
     $item->setPrice($itemPrice);
 }
 /**
  * Calculates total prices of all items given in data array.
  *
  * @param array $itemsData
  * @param string $currency
  * @param string $locale
  *
  * @return array
  */
 public function retrieveItemPrices($itemsData, $currency, $locale)
 {
     $items = [];
     // Prepare item data.
     foreach ($itemsData as $itemData) {
         $useProductsPrice = false;
         if (isset($itemData['useProductsPrice']) && $itemData['useProductsPrice'] == true) {
             $useProductsPrice = $itemData['useProductsPrice'];
         }
         // Add and remove necessary data for calculation.
         $itemData = $this->setDefaultData($itemData);
         $itemData = $this->unsetUneccesaryData($itemData);
         // Generate item.
         $item = $this->getItemManager()->save($itemData, $locale);
         $item->setUseProductsPrice($useProductsPrice);
         // Calculate total net price of item.
         $itemPrice = $this->itemPriceCalculator->calculateItemNetPrice($item, $currency, $useProductsPrice, $this->isItemGrossPrice($itemData));
         $itemTotalNetPrice = $this->itemPriceCalculator->calculateItemTotalNetPrice($item, $currency, $useProductsPrice, $this->isItemGrossPrice($itemData));
         $item->setPrice($itemPrice);
         $item->setTotalNetPrice($itemTotalNetPrice);
         $items[] = $item;
     }
     return ['items' => $items];
 }