コード例 #1
0
ファイル: Discount.php プロジェクト: pavelnovitsky/magento2
 /**
  * Recalculate child discount. Separate discount between children
  *
  * @param AbstractItem $child
  * @return $this
  */
 protected function _recalculateChildDiscount($child)
 {
     $item = $child->getParentItem();
     $prices = array('base' => $item->getBaseOriginalPrice(), 'current' => $item->getPrice());
     $keys = array('discount_amount', 'original_discount_amount');
     foreach ($keys as $key) {
         $child->setData($key, $child->getData($key) * $child->getPrice() / $prices['current']);
         $child->setData('base_' . $key, $child->getData('base_' . $key) * $child->getPrice() / $prices['base']);
     }
     return $this;
 }
コード例 #2
0
ファイル: Tax.php プロジェクト: Atlis/docker-magento2
 /**
  * Map an item to item data object
  *
  * @param ItemBuilder $itemBuilder
  * @param AbstractItem $item
  * @param bool $priceIncludesTax
  * @param bool $useBaseCurrency
  * @param string $parentCode
  * @return ItemDataObject
  */
 protected function mapItem(ItemBuilder $itemBuilder, AbstractItem $item, $priceIncludesTax, $useBaseCurrency, $parentCode = null)
 {
     if (!$item->getSequence()) {
         $sequence = 'sequence-' . $this->getNextIncrement();
         $item->setSequence($sequence);
     }
     $itemBuilder->setCode($item->getSequence());
     $itemBuilder->setQuantity($item->getQty());
     $itemBuilder->setTaxClassId($item->getProduct()->getTaxClassId());
     $itemBuilder->setTaxIncluded($priceIncludesTax);
     $itemBuilder->setType('product');
     //TODO: find a place to define constants
     if ($item->getParentItem()) {
         $itemBuilder->setParentCode($item->getParentItem()->getId());
     }
     if ($useBaseCurrency) {
         if (!$item->getBaseTaxCalculationPrice()) {
             $item->setBaseTaxCalculationPrice($item->getBaseCalculationPriceOriginal());
         }
         $itemBuilder->setUnitPrice($item->getBaseTaxCalculationPrice());
         $itemBuilder->setDiscountAmount($item->getBaseDiscountAmount());
     } else {
         if (!$item->getTaxCalculationPrice()) {
             $item->setTaxCalculationPrice($item->getCalculationPriceOriginal());
         }
         $itemBuilder->setUnitPrice($item->getTaxCalculationPrice());
         $itemBuilder->setDiscountAmount($item->getDiscountAmount());
     }
     $itemBuilder->setParentCode($parentCode);
     return $itemBuilder->create();
 }