Esempio n. 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);
     }
 }
Esempio n. 2
0
 /**
  * Correct product amount to add to cart
  *
  * @param \XLite\Model\OrderItem $item   Product to add
  * @param integer                $amount Amount of product
  *
  * @return integer
  */
 protected function correctAmountToAdd(\XLite\Model\OrderItem $item, $amount)
 {
     if ($item && $item->getProduct()->mustHaveVariants()) {
         $item->setVariant($item->getProduct()->getVariantByAttributeValuesIds($item->getAttributeValuesIds()));
     }
     return parent::correctAmountToAdd($item, $amount);
 }
Esempio n. 3
0
 /**
  * Returns deleted product for fake items
  *
  * @return \XLite\Model\Product
  */
 public function getProduct()
 {
     if ($this->isXpcFakeItem()) {
         return $this->getDeletedProduct();
     } else {
         return parent::getProduct();
     }
 }
 /**
  * Show message about wrong product amount
  *
  * @param \XLite\Model\OrderItem $item Order item
  *
  * @return void
  */
 protected function processInvalidAmountError(\XLite\Model\OrderItem $item)
 {
     \XLite\Core\TopMessage::addWarning('You tried to buy more items of "{{product}}" product {{description}} than are in stock. We have {{amount}} item(s) only. Please adjust the product quantity.', array('product' => $item->getProduct()->getName(), 'description' => $item->getExtendedDescription(), 'amount' => $item->getProductAvailableAmount()));
 }
Esempio n. 5
0
File: Cart.php Progetto: kingsj/core
 /**
  * Correct product amount to add to cart
  *
  * @param \XLite\Model\OrderItem $item   Product to add
  * @param integer                $amount Amount of product
  *
  * @return integer
  */
 protected function correctAmountToAdd(\XLite\Model\OrderItem $item, $amount)
 {
     $amount = $this->correctAmountAsProduct($item->getProduct(), $amount);
     if (!$this->checkAmountToAdd($item, $amount)) {
         $amount = $this->getProductAvailableAmount($item);
         $this->processInvalidAmountError($item->getProduct(), $amount);
     }
     return $amount;
 }
Esempio n. 6
0
 /**
  * Check - is item product id equal specified product id
  *
  * @param \XLite\Model\OrderItem $item      Item
  * @param integer                $productId Product id
  *
  * @return boolean
  */
 public function isItemProductIdEqual(\XLite\Model\OrderItem $item, $productId)
 {
     return $item->getProduct()->getProductId() == $productId;
 }
Esempio n. 7
0
 /**
  * Check order item and return true if this is valid
  *
  * @param \XLite\Model\OrderItem $entity Order item entity
  *
  * @return boolean
  */
 protected function isValidEntity($entity)
 {
     $result = 0 < $entity->getAmount();
     if ($result && ($entity->hasAttributeValues() || $entity->getProduct()->hasEditableAttributes())) {
         $result = array_keys($entity->getAttributeValuesIds()) == $entity->getProduct()->getEditableAttributesIds();
     }
     return $result;
 }
Esempio n. 8
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);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function getProduct()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getProduct', array());
     return parent::getProduct();
 }