Exemplo n.º 1
0
 /**
  * @param array $total
  * @return Total|array
  */
 protected function convert($total)
 {
     if ($total instanceof Total) {
         return $total;
     }
     if (count(array_column($total, 'code')) > 0) {
         $totals = [];
         foreach ($total as $item) {
             $totals[] = $this->totalFactory->create('Magento\\Quote\\Model\\Quote\\Address\\Total')->setData($item);
         }
         return $totals;
     }
     return $this->totalFactory->create('Magento\\Quote\\Model\\Quote\\Address\\Total')->setData($total);
 }
Exemplo n.º 2
0
 /**
  * Init model class by configuration
  *
  * @param string $class
  * @param string $totalCode
  * @param array $totalConfig
  * @return \Magento\Quote\Model\Quote\Address\Total\AbstractTotal
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _initModelInstance($class, $totalCode, $totalConfig)
 {
     $model = $this->_totalFactory->create($class);
     if (!$model instanceof \Magento\Quote\Model\Quote\Address\Total\AbstractTotal) {
         throw new \Magento\Framework\Exception\LocalizedException(__('The address total model should be extended from \\Magento\\Quote\\Model\\Quote\\Address\\Total\\AbstractTotal.'));
     }
     $model->setCode($totalCode);
     $this->_modelsConfig[$totalCode] = $this->_prepareConfigArray($totalCode, $totalConfig);
     $this->_modelsConfig[$totalCode] = $model->processConfigArray($this->_modelsConfig[$totalCode], $this->_store);
     return $model;
 }
 /**
  * @param \Magento\Quote\Model\Quote $quote
  * @param Address $address
  * @return Address\Total
  */
 public function collectAddressTotals(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address $address)
 {
     /** @var \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment */
     $shippingAssignment = $this->shippingAssignmentFactory->create();
     /** @var \Magento\Quote\Api\Data\ShippingInterface $shipping */
     $shipping = $this->shippingFactory->create();
     $shipping->setMethod($address->getShippingMethod());
     $shipping->setAddress($address);
     $shippingAssignment->setShipping($shipping);
     $shippingAssignment->setItems($address->getAllItems());
     /** @var \Magento\Quote\Model\Quote\Address\Total $total */
     $total = $this->totalFactory->create('Magento\\Quote\\Model\\Quote\\Address\\Total');
     $this->eventManager->dispatch('sales_quote_address_collect_totals_before', ['quote' => $quote, 'shipping_assignment' => $shippingAssignment, 'total' => $total]);
     foreach ($this->collectorList->getCollectors($quote->getStoreId()) as $collector) {
         /** @var CollectorInterface $collector */
         $collector->collect($quote, $shippingAssignment, $total);
     }
     $this->eventManager->dispatch('sales_quote_address_collect_totals_after', ['quote' => $quote, 'shipping_assignment' => $shippingAssignment, 'total' => $total]);
     $address->addData($total->getData());
     $address->setAppliedTaxes($total->getAppliedTaxes());
     return $total;
 }
Exemplo n.º 4
0
 /**
  * Add total data or model
  *
  * @param \Magento\Quote\Model\Quote\Total|array $total
  * @return $this
  */
 public function addTotal($total)
 {
     if (is_array($total)) {
         $totalInstance = $this->_addressTotalFactory->create('Magento\\Quote\\Model\\Quote\\Address\\Total')->setData($total);
     } elseif ($total instanceof \Magento\Quote\Model\Quote\Total) {
         $totalInstance = $total;
     }
     $totalInstance->setAddress($this);
     $this->_totals[$totalInstance->getCode()] = $totalInstance;
     return $this;
 }
Exemplo n.º 5
0
 /**
  * Add total data or model
  *
  * @param \Magento\Quote\Model\Quote\Address\Total|array $total
  * @return $this
  */
 public function addTotal($total)
 {
     $addressTotal = null;
     if (is_array($total)) {
         /** @var \Magento\Quote\Model\Quote\Address\Total $addressTotal */
         $addressTotal = $this->_addressTotalFactory->create('Magento\\Quote\\Model\\Quote\\Address\\Total');
         $addressTotal->setData($total);
     } elseif ($total instanceof \Magento\Quote\Model\Quote\Address\Total) {
         $addressTotal = $total;
     }
     if ($addressTotal !== null) {
         $addressTotal->setAddress($this);
         $this->_totals[$addressTotal->getCode()] = $addressTotal;
     }
     return $this;
 }