Пример #1
0
 /**
  * @param \Magento\Quote\Model\Quote\Item\AbstractItem $item
  * @param bool $isFreeShipping
  * @return void
  */
 protected function applyToChildren(\Magento\Quote\Model\Quote\Item\AbstractItem $item, $isFreeShipping)
 {
     if ($item->getHasChildren() && $item->isChildrenCalculated()) {
         foreach ($item->getChildren() as $child) {
             $this->calculator->processFreeShipping($child);
             if ($isFreeShipping) {
                 $child->setFreeShipping($isFreeShipping);
             }
         }
     }
 }
Пример #2
0
    /**
     * Returns applied weee taxes
     *
     * @param \Magento\Quote\Model\Quote\Item\AbstractItem $item
     * @return array
     */
    public function getApplied($item)
    {
        if ($item instanceof \Magento\Quote\Model\Quote\Item\AbstractItem) {
            if ($item->getHasChildren() && $item->isChildrenCalculated()) {
                $result = [];
                foreach ($item->getChildren() as $child) {
                    $childData = $this->getApplied($child);
                    if (is_array($childData)) {
                        $result = array_merge($result, $childData);
                    }
                }
                return $result;
            }
        }

        // if order item data is old enough then weee_tax_applied might not be valid
        $data = $item->getWeeeTaxApplied();
        if (empty($data)) {
            return [];
        }
        return \Zend_Json::decode($item->getWeeeTaxApplied());
    }
Пример #3
0
 /**
  * Distribute discount at parent item to children items
  *
  * @param \Magento\Quote\Model\Quote\Item\AbstractItem $item
  * @return $this
  */
 protected function distributeDiscount(\Magento\Quote\Model\Quote\Item\AbstractItem $item)
 {
     $parentBaseRowTotal = $item->getBaseRowTotal();
     $keys = ['discount_amount', 'base_discount_amount', 'original_discount_amount', 'base_original_discount_amount'];
     $roundingDelta = [];
     foreach ($keys as $key) {
         //Initialize the rounding delta to a tiny number to avoid floating point precision problem
         $roundingDelta[$key] = 1.0E-7;
     }
     foreach ($item->getChildren() as $child) {
         $ratio = $child->getBaseRowTotal() / $parentBaseRowTotal;
         foreach ($keys as $key) {
             if (!$item->hasData($key)) {
                 continue;
             }
             $value = $item->getData($key) * $ratio;
             $roundedValue = $this->priceCurrency->round($value + $roundingDelta[$key]);
             $roundingDelta[$key] += $value - $roundedValue;
             $child->setData($key, $roundedValue);
         }
     }
     foreach ($keys as $key) {
         $item->setData($key, 0);
     }
     return $this;
 }
Пример #4
0
 /**
  * Recalculate parent item amounts based on children results
  *
  * @param   \Magento\Quote\Model\Quote\Item\AbstractItem $item
  * @return  void
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 protected function recalculateParent(\Magento\Quote\Model\Quote\Item\AbstractItem $item)
 {
     $associatedTaxables = [];
     foreach ($item->getChildren() as $child) {
         $associatedTaxables = array_merge($associatedTaxables, $child->getAssociatedTaxables());
     }
     $item->setAssociatedTaxables($associatedTaxables);
 }