Beispiel #1
0
 /**
  * Change product quantity in stock if needed
  *
  * @param \XLite\Model\OrderItem $entity Order item entity
  *
  * @return void
  */
 protected function changeItemAmountInStock($entity)
 {
     if ($entity->getVariant()) {
         $oldVariant = $this->orderItemsData[$entity->getItemId()]['variant'];
         $newVariant = $entity->getVariant();
         if ($this->isItemDataChangedVariant($oldVariant, $newVariant)) {
             // Return old variant amount to stock
             if (!$oldVariant->getDefaultAmount()) {
                 $oldVariant->changeAmount($this->orderItemsData[$entity->getItemId()]['amount']);
             } else {
                 $entity->getProduct()->getInventory()->changeAmount($this->orderItemsData[$entity->getItemId()]['amount']);
             }
             // Get new variant amount from stock
             if (!$newVariant->getDefaultAmount()) {
                 $newVariant->changeAmount(-1 * $entity->getAmount());
             } else {
                 $entity->getProduct()->getInventory()->changeAmount(-1 * $entity->getAmount());
             }
         } else {
             parent::changeItemAmountInStock($entity);
         }
     } else {
         parent::changeItemAmountInStock($entity);
     }
 }
Beispiel #2
0
 /**
  * Get item inventory delta
  *
  * @param \XLite\Model\OrderItem $item Current item
  * @param integer                $sign Flag; "1" or "-1"
  *
  * @return integer
  */
 protected function getItemInventoryAmount(\XLite\Model\OrderItem $item, $sign)
 {
     return $sign * $item->getAmount();
 }
Beispiel #3
0
 /**
  * Return false if order item amount exceeds maximum allowed value
  *
  * @param \XLite\Model\OrderItem $entity Order item entity
  *
  * @return boolean
  */
 protected function isItemHasWrongAmount($entity)
 {
     $oldAmount = $this->orderItemsData[$entity->getItemId()]['amount'];
     $maxAmount = $entity->getProductAvailableAmount();
     return $oldAmount + $maxAmount < $entity->getAmount();
 }
Beispiel #4
0
 /**
  * Return true if item amount limit is reached
  *
  * @param \XLite\Model\OrderItem $item Order item
  *
  * @return boolean
  */
 protected function isItemLimitReached($item)
 {
     $result = false;
     $product = $item->getObject();
     if ($product && $product->mustHaveVariants()) {
         $variant = $item->getVariant();
         $result = $variant && $variant->getAmount() <= $item->getAmount();
     } else {
         $result = parent::isItemLimitReached($item);
     }
     return $result;
 }
Beispiel #5
0
 /**
  * Prepare order item before price calculation
  *
  * @param \XLite\Model\OrderItem $item       Order item
  * @param array                  $attributes Attributes
  *
  * @return void
  */
 protected function prepareItemBeforePriceCalculation(\XLite\Model\OrderItem $item, array $attributes)
 {
     \XLite\Core\Request::getInstance()->oldAmount = $item->getAmount();
     $item->setAmount(\XLite\Core\Request::getInstance()->amount);
     if ($attributes) {
         $attributeValues = $item->getProduct()->prepareAttributeValues($attributes);
         $item->setAttributeValues($attributeValues);
     }
 }
 /**
  * @param \XLite\Model\OrderItem $orderItem Order item
  * 
  * @return array
  */
 protected function getBasketLine(\XLite\Model\OrderItem $orderItem)
 {
     return array('lineId' => $orderItem->getSku(), 'currency' => $orderItem->getOrder()->getCurrency()->getCode(), 'quantity' => $orderItem->getAmount(), 'unitPrice' => array('price' => array('value' => $orderItem->getItemNetPrice()), 'codPrice' => array(), 'dutiableValue' => array('value' => $orderItem->getItemNetPrice())), 'commodity' => array('merchantComRefId' => $orderItem->getSku(), 'descriptions' => array(), 'hsCodes' => array(), 'imageUrls' => array(), 'identifiers' => array(), 'attributes' => array(), 'hazmats' => array(), 'categories' => array()), 'kitContents' => array());
 }
 /**
  * {@inheritDoc}
  */
 public function getAmount()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getAmount', array());
     return parent::getAmount();
 }