Example #1
0
 /**
  * Updates changed prices
  *
  * @param array $items
  *
  * @return bool
  */
 public function updateCartPrices($items)
 {
     // set prices to changed
     $hasChanged = $this->priceCalculation->setPricesOfChanged($items);
     if ($hasChanged) {
         $this->em->flush();
     }
     return $hasChanged;
 }
Example #2
0
 /**
  * Function updates the api-entity, like price-calculations.
  *
  * @param Order $apiOrder
  */
 public function updateApiEntity(Order $apiOrder, $locale)
 {
     $items = $apiOrder->getItems();
     // Perform price calculation.
     $groupedPrices = [];
     $supplierItems = [];
     $prices = $this->priceCalculator->calculate($items, $apiOrder->getNetShippingCosts(), $groupedPrices, $supplierItems, $this->defaultCurrency);
     if ($supplierItems) {
         $supplierItems = array_values($supplierItems);
         // Update media api entities.
         $this->createMediaForSupplierItems($supplierItems, $locale);
         // Set grouped items.
         $apiOrder->setSupplierItems($supplierItems);
     }
     $this->createMediaForItems($items, $locale);
     // Check if any price in cart has changed.
     $hasChangedPrices = false;
     foreach ($items as $item) {
         if ($item->getPriceChange()) {
             $hasChangedPrices = true;
             break;
         }
     }
     $apiOrder->setHasChangedPrices($hasChangedPrices);
     // Set total prices.
     $apiOrder->getEntity()->setTotalNetPrice($prices['totalNetPrice']);
     $apiOrder->getEntity()->setTotalPrice($prices['totalPrice']);
     $apiOrder->getEntity()->setTotalRecurringNetPrice($prices['totalRecurringNetPrice']);
     $apiOrder->getEntity()->setTotalRecurringPrice($prices['totalRecurringPrice']);
     $apiOrder->getEntity()->setShippingCosts($prices['shippingCosts']);
 }