/** * Get item * * @return \XLite\Model\OrderItem */ public function getItem() { if (!isset($this->item)) { // Initialize order item from request param item_id if (is_numeric(\XLite\Core\Request::getInstance()->item_id)) { $item = \XLite\Core\Database::getRepo('XLite\\Model\\OrderItem')->find(\XLite\Core\Request::getInstance()->item_id); if ($item && $item->getProduct() && $item->hasAttributeValues()) { $this->item = $item; } } } if (!isset($this->item) && \XLite\Core\Request::getInstance()->productId) { // Initialize order item from productId param $product = \XLite\Core\Database::getRepo('XLite\\Model\\Product')->find(\XLite\Core\Request::getInstance()->productId); if ($product) { $this->item = new \XLite\Model\OrderItem(); $this->item->setProduct($product); $this->item->setAttributeValues($product->prepareAttributeValues()); } } if (!isset($this->item)) { // Order item was not initialized: set to false to prevent re-initialization $this->item = false; } return $this->item; }
/** * Check - item price is controlled by server or not * * @return boolean */ public function isPriceControlledServer() { $result = parent::isPriceControlledServer(); if (!$result && $this->getProduct()) { $model = \XLite\Core\Database::getRepo('XLite\\Module\\CDev\\Wholesale\\Model\\WholesalePrice')->findOneBy(array('product' => $this->getProduct())); $result = !!$model; } return $result; }
/** * Get price * * @return float */ public function getPrice() { $price = parent::getPrice(); $product = $this->getProduct(); if (is_object($product) && $product->getParticipateSale()) { $price = $product->getSalePrice(); } return $price; }
/** * Return true if order item is forced to be 'free shipping' item * * @return boolean */ public function isFreeShipping() { $result = parent::isFreeShipping(); if (!$result && $this->getOrder()->getUsedCoupons()) { foreach ($this->getOrder()->getUsedCoupons() as $coupon) { if (!$coupon->isDeleted() && $coupon->getCoupon()->isFreeShipping() && $coupon->getCoupon()->isValidForProduct($this->getProduct())) { // Product is affected by discount coupon 'FREE SHIPPING' $result = true; break; } } } return $result; }
/** * 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(); }
/** * {@inheritDoc} */ public function prepareEntityBeforeCommit($type) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'prepareEntityBeforeCommit', array($type)); return parent::prepareEntityBeforeCommit($type); }
/** * 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; }
/** * Get item basis * * @param \XLite\Model\OrderItem $item Order item * * @return float */ protected function getItemBasis($item) { $basis = 0; $formulaParts = explode('+', $this->getTaxableBaseType()); foreach ($formulaParts as $part) { switch ($part) { case 'ST': $basis += $item->getSubtotal(); break; case 'DST': $basis += $item->getDiscountedSubtotal(); break; case 'SH': $basis += $item->getShippingCost(); break; } } return $basis; }
/** * Get price * * @return float */ public function getClearPrice() { $this->setWholesaleValues(); return parent::getClearPrice(); }
/** * 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())); }
/** * Clone order item object * * @return \XLite\Model\OrderItem */ public function cloneEntity() { $newItem = parent::cloneEntity(); if ($this->getVariant()) { $newItem->setVariant($this->getVariant()); } return $newItem; }
/** * Get attribute input name * * @param \XLite\Model\OrderItem $entity Order item * @param \XLite\Model\OrderItem\AttributeValue $av Attribute value * * @return string */ protected function getAttributeInputName(\XLite\Model\OrderItem $entity, \XLite\Model\OrderItem\AttributeValue $av) { return $this->getIdx() > 0 ? 'order_items[' . $entity->getItemId() . '][attribute_values][' . $this->getAttributeId($av) . ']' : 'new[' . $this->getIdx() . '][attribute_values][' . $this->getAttributeId($av) . ']'; }
/** * Check - is item variant id equal specified variant id * * @param \XLite\Model\OrderItem $item Item * @param integer $variantId Variant id * * @return boolean */ public function isItemVariantIdEqual(\XLite\Model\OrderItem $item, $variantId) { return $item->getVariant() && $item->getVariant()->getId() == $variantId; }
/** * Check if the requested amount is available for the product * * @param \XLite\Model\OrderItem $item Order item to add * @param integer $amount Amount to check OPTIONAL * * @return integer */ protected function checkAmount(\XLite\Model\OrderItem $item, $amount = null) { return $item->getVariant() && !$item->getVariant()->getDefaultAmount() ? ($amount ?: 0) < $item->getVariant()->getAvailableAmount() : parent::checkAmount($item, $amount); }
/** * @param \XLite\Model\OrderItem $item Order item * * @return boolean */ protected function needMoreAttributesLink(\XLite\Model\OrderItem $item) { return $item->getAttributeValuesCount() > $this->getMaxAttributesCount(); }
/** * Assemble recalculate item event * * @param \XLite\Model\OrderItem $item Order item * * @return array */ protected function assembleRecalculateItemEvent(\XLite\Model\OrderItem $item) { $maxAmount = $item->getProductAvailableAmount(); if ($item->isPersistent() && \XLite\Core\Request::getInstance()->oldAmount) { $maxAmount += \XLite\Core\Request::getInstance()->oldAmount; \XLite\Core\Request::getInstance()->oldAmount = null; } return array('item_id' => $item->getItemId(), 'requestId' => \XLite\Core\Request::getInstance()->requestId, 'price' => $item->getNetPrice(), 'max_qty' => $maxAmount); }
/** * Check item sku equal * * @param \XLite\Model\OrderItem $item Order item * @param string $sku Sku * * @return boolean */ public function checkItemSKUEqual(\XLite\Model\OrderItem $item, $sku) { return $item->getSKU() == $sku; }
/** * @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()); }
/** * 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(); }
/** * 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); } }
/** * 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; }
/** * Constructor * * @param array $data Entity properties OPTIONAL * * @return void */ public function __construct(array $data = array()) { $this->pinCodes = new \Doctrine\Common\Collections\ArrayCollection(); parent::__construct($data); }
/** * Check if the item is valid to clone through the Re-order functionality * * @return boolean */ public function isValidToClone() { if ($this->isXpcFakeItem()) { $result = false; } else { $result = parent::isValidToClone(); } return $result; }
/** * Check if the product of the order item is deleted one in the store * * @param \XLite\Model\OrderItem $item Order item * @param boolean $data Flag * * @return boolean */ public function checkIsAvailableToOrder(\XLite\Model\OrderItem $item, $data) { return $data !== $item->isValidToClone(); }
/** * Count available for parcel order items * * @param \XLite\Model\OrderItem $orderItem Order item * * @return integer */ public function getAmountInParcel($orderItem) { $result = 0; foreach ($this->getParcelItems() as $item) { if ($item->getOrderItem() && $item->getOrderItem()->getItemId() == $orderItem->getItemId()) { $result += $item->getAmount(); } } return $result; }
/** * Add order item surcharge * * @param \XLite\Model\OrderItem $item Order item * @param string $code Surcharge code * @param float $value Value * @param boolean $include Include flag OPTIONAL * @param boolean $available Availability flag OPTIONAL * * @return \XLite\Model\OrderItem\Surcharge */ protected function addOrderItemSurcharge(\XLite\Model\OrderItem $item, $code, $value, $include = false, $available = true) { $surcharge = new \XLite\Model\OrderItem\Surcharge(); $surcharge->setType($this->type); $surcharge->setCode($code); $surcharge->setValue($value); $surcharge->setInclude($include); $surcharge->setAvailable($available); $surcharge->setClass(get_called_class()); $info = $this->getSurchargeInfo($surcharge); $surcharge->setName($info->name); $item->addSurcharges($surcharge); $surcharge->setOwner($item); return $surcharge; }
/** * Return true if order item must be excluded from shipping rates calculations * * @param \XLite\Model\OrderItem $item Order item * * @return boolean */ protected function isIgnoreShippingCalculation($item) { return $item->getObject() && ($item->getObject()->getFreeShip() || $this->isIgnoreProductsWithFixedFee() && 0 < $item->getObject()->getFreightFixedFee()); }
/** * Constructor * * @param array $data Entity properties OPTIONAL * * @return void */ public function __construct(array $data = array()) { parent::__construct($data); $this->privateAttachments = new \Doctrine\Common\Collections\ArrayCollection(); }