/** * Get either shipping rate code or empty value on error * * @param \Magento\Framework\DataObject $rate * @return string */ public function renderShippingRateValue(\Magento\Framework\DataObject $rate) { if ($rate->getErrorMessage()) { return ''; } return $rate->getCode(); }
/** * Method is needed for specific actions to change given quote options values * according current product type logic * Example: the catalog inventory validation of decimal qty can change qty to int, * so need to change quote item qty option value too. * * @param array $options * @param \Magento\Framework\DataObject $option * @param mixed $value * @param \Magento\Catalog\Model\Product $product * @return $this */ public function updateQtyOption($options, \Magento\Framework\DataObject $option, $value, $product) { $optionProduct = $option->getProduct($product); $optionUpdateFlag = $option->getHasQtyOptionUpdate(); $optionCollection = $this->getOptionsCollection($product); $selections = $this->getSelectionsCollection($optionCollection->getAllIds(), $product); foreach ($selections as $selection) { if ($selection->getProductId() == $optionProduct->getId()) { foreach ($options as &$option) { if ($option->getCode() == 'selection_qty_' . $selection->getSelectionId()) { if ($optionUpdateFlag) { $option->setValue(intval($option->getValue())); } else { $option->setValue($value); } } } } } return $this; }
/** * Add new total to totals array before specific total or after first total by default * * @param \Magento\Framework\DataObject $total * @param null|string $before * @return $this */ public function addTotalBefore(\Magento\Framework\DataObject $total, $before = null) { if ($before !== null) { if (!is_array($before)) { $before = [$before]; } foreach ($before as $beforeTotals) { if (isset($this->_totals[$beforeTotals])) { $totals = []; foreach ($this->_totals as $code => $item) { if ($code == $beforeTotals) { $totals[$total->getCode()] = $total; } $totals[$code] = $item; } $this->_totals = $totals; return $this; } } } $totals = []; $first = array_shift($this->_totals); $totals[$first->getCode()] = $first; $totals[$total->getCode()] = $total; foreach ($this->_totals as $code => $item) { $totals[$code] = $item; } $this->_totals = $totals; return $this; }