Example #1
0
File: Cart.php Project: kingsj/core
 /**
  * Correct product amount to add to cart.
  * Common correction amount of order item as a product unit
  * irrespective of customer selections or order conditions (options/variants/offers)
  *
  * @param \XLite\Model\Product $product Product to add
  * @param integer|null         $amount  Amount of product.
  *                                      Null is given when there is no amount in request.
  *
  * @return integer
  */
 protected function correctAmountAsProduct(\XLite\Model\Product $product, $amount)
 {
     if (is_null($amount)) {
         $amount = $product->getInventory() ? $product->getInventory()->getLowAvailableAmount() : 1;
     }
     return $amount;
 }
Example #2
0
 /**
  * Register the change amount inventory
  *
  * @param integer              $orderId Order identificator
  * @param \XLite\Model\Product $product Product object
  * @param integer              $delta   Inventory delta changes
  *
  * @return void
  */
 public function registerChangeAmount($orderId, $product, $delta)
 {
     $inventory = $product->getInventory();
     if ($inventory->getEnabled()) {
         $this->registerEvent($orderId, static::CODE_CHANGE_AMOUNT, $this->getOrderChangeAmountDescription($orderId, $delta, $inventory), $this->getOrderChangeAmountData($orderId, $product->getName(), $inventory->getPublicAmount(), $delta));
     }
 }
Example #3
0
 /**
  * Import inventory data
  *
  * @param \XLite\Model\Product $product Product
  * @param string               $data    Data
  * @param string               $name    Cell name
  *
  * @return void
  */
 protected function importInventory(\XLite\Model\Product $product, $data, $name)
 {
     if ('inventoryEnabled' == $name) {
         $name = 'enabled';
     }
     $method = 'set' . ucfirst($name);
     $product->getInventory()->{$method}($data);
     if (!$product->getInventory()->getInventoryId()) {
         $product->setInventory($product->getInventory());
         $product->getInventory()->setProduct($product);
     }
 }
Example #4
0
 /**
  * Import 'low limit level' value
  *
  * @param \XLite\Model\Product $model  Product
  * @param mixed                $value  Value
  * @param array                $column Column info
  *
  * @return void
  */
 protected function importLowLimitLevelColumn(\XLite\Model\Product $model, $value, array $column)
 {
     $model->getInventory()->setLowLimitAmount(abs((int) $value));
 }
 /**
  * {@inheritDoc}
  */
 public function getInventory()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getInventory', array());
     return parent::getInventory();
 }