Esempio n. 1
0
 /**
  * Map an item to item data object
  *
  * @param ItemBuilder $itemBuilder
  * @param AbstractItem $item
  * @param bool $priceIncludesTax
  * @param bool $useBaseCurrency
  * @param string $parentCode
  * @return ItemDataObject
  */
 public function mapItem(ItemBuilder $itemBuilder, AbstractItem $item, $priceIncludesTax, $useBaseCurrency, $parentCode = null)
 {
     if (!$item->getTaxCalculationItemId()) {
         $sequence = 'sequence-' . $this->getNextIncrement();
         $item->setTaxCalculationItemId($sequence);
     }
     $itemBuilder->setCode($item->getTaxCalculationItemId());
     $itemBuilder->setQuantity($item->getQty());
     $itemBuilder->setTaxClassKey($itemBuilder->getTaxClassKeyBuilder()->setType(TaxClassKey::TYPE_ID)->setValue($item->getProduct()->getTaxClassId())->create());
     $itemBuilder->setTaxIncluded($priceIncludesTax);
     $itemBuilder->setType(self::ITEM_TYPE_PRODUCT);
     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();
 }
Esempio n. 2
0
 /**
  * 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();
 }