Esempio n. 1
0
 /**
  * Init model class by configuration
  *
  * @param string $class
  * @param string $totalCode
  * @param array $totalConfig
  * @return \Magento\Sales\Model\Quote\Address\Total\AbstractTotal
  * @throws \Magento\Framework\Model\Exception
  */
 protected function _initModelInstance($class, $totalCode, $totalConfig)
 {
     $model = $this->_totalFactory->create($class);
     if (!$model instanceof \Magento\Sales\Model\Quote\Address\Total\AbstractTotal) {
         throw new \Magento\Framework\Model\Exception(__('The address total model should be extended from \\Magento\\Sales\\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;
 }
Esempio n. 2
0
 /**
  * Add total data or model
  *
  * @param \Magento\Sales\Model\Quote\Total|array $total
  * @return $this
  */
 public function addTotal($total)
 {
     if (is_array($total)) {
         $totalInstance = $this->_addressTotalFactory->create('Magento\\Sales\\Model\\Quote\\Address\\Total')->setData($total);
     } elseif ($total instanceof \Magento\Sales\Model\Quote\Total) {
         $totalInstance = $total;
     }
     $totalInstance->setAddress($this);
     $this->_totals[$totalInstance->getCode()] = $totalInstance;
     return $this;
 }