/** * Validate stock of a quoteItem * * @param Mage_Sales_Model_Quote_Item $item * @param float $priceInclTax * @param float $priceExclTax * @return ShopgateCartItem $result */ public function validateStock(Mage_Sales_Model_Quote_Item $item, $priceInclTax, $priceExclTax) { /** @var Mage_Catalog_Model_Product $product */ $product = $item->getProduct(); /** @var Mage_CatalogInventory_Model_Stock_Item $stockItem */ $stockItem = $product->getStockItem(); $isBuyable = true; if ($product->isConfigurable()) { $parent = $product; $product = $product->getCustomOption('simple_product')->getProduct(); $product->setShopgateItemNumber($parent->getShopgateItemNumber()); $product->setShopgateOptions($parent->getShopgateOptions()); $product->setShopgateInputs($parent->getShopgateInputs()); $product->setShhopgateAttributes($parent->getShhopgateAttributes()); $stockItem = $item->getProduct()->getCustomOption('simple_product')->getProduct()->getStockItem(); } $errors = array(); if (Mage::helper('shopgate/config')->getIsMagentoVersionLower1410()) { $checkIncrements = Mage::helper('shopgate')->checkQtyIncrements($stockItem, $item->getQty()); } else { $checkIncrements = $stockItem->checkQtyIncrements($item->getQty()); } if ($stockItem->getManageStock() && !$product->isSaleable() && (!$stockItem->getBackorders() || !$stockItem->getIsInStock())) { $isBuyable = false; $error = array(); $error['type'] = ShopgateLibraryException::CART_ITEM_OUT_OF_STOCK; $error['message'] = ShopgateLibraryException::getMessageFor(ShopgateLibraryException::CART_ITEM_OUT_OF_STOCK); $errors[] = $error; } else { if ($stockItem->getManageStock() && !$stockItem->checkQty($item->getQty()) && !$stockItem->getBackorders()) { $isBuyable = false; $error = array(); $error['type'] = ShopgateLibraryException::CART_ITEM_REQUESTED_QUANTITY_NOT_AVAILABLE; $error['message'] = ShopgateLibraryException::getMessageFor(ShopgateLibraryException::CART_ITEM_REQUESTED_QUANTITY_NOT_AVAILABLE); $errors[] = $error; } else { if ($stockItem->getManageStock() && $checkIncrements->getHasError()) { $isBuyable = false; $error = array(); $error['type'] = ShopgateLibraryException::CART_ITEM_REQUESTED_QUANTITY_NOT_AVAILABLE; $error['message'] = ShopgateLibraryException::getMessageFor(ShopgateLibraryException::CART_ITEM_REQUESTED_QUANTITY_NOT_AVAILABLE); $errors[] = $error; $stockItem->setQty((int) ($item->getQtyToAdd() / $stockItem->getQtyIncrements()) * $stockItem->getQtyIncrements()); } } } $qtyBuyable = $isBuyable ? (int) $item->getQty() : (int) $stockItem->getQty(); return Mage::helper('shopgate')->generateShopgateCartItem($product, $isBuyable, $qtyBuyable, $priceInclTax, $priceExclTax, $errors, (int) $stockItem->getQty()); }
/** * Get an estimated delivery message for a quote item. * * @param Mage_Sales_Model_Quote_Item * @return string */ public function getEddMessage(Mage_Sales_Model_Quote_Item $item) { /** @var string $singularOrPluralItem */ $singularOrPluralItem = (int) $item->getQty() > 1 ? 's' : ''; /** @var EbayEnterprise_Inventory_Model_Details_Item | Varien_Object | null $eddItem */ $eddItem = $this->detailService->getDetailsForItem($item) ?: $this->inventoryHelper->getStreetDateForBackorderableItem($item); return $eddItem ? $this->inventoryHelper->__($this->inventoryConfig->estimatedDeliveryTemplate, $singularOrPluralItem, $eddItem->getDeliveryWindowFromDate()->format('m/d/y'), $eddItem->getDeliveryWindowToDate()->format('m/d/y')) : ''; }
public function importQuoteItem(Mage_Sales_Model_Quote_Item $quoteItem) { $this->setQuoteItemId($quoteItem->getId())->setProductId($quoteItem->getProductId())->setProduct($quoteItem->getProduct())->setSuperProductId($quoteItem->getSuperProductId())->setSuperProduct($quoteItem->getSuperProduct())->setSku($quoteItem->getSku())->setImage($quoteItem->getImage())->setName($quoteItem->getName())->setDescription($quoteItem->getDescription())->setWeight($quoteItem->getWeight())->setPrice($quoteItem->getPrice())->setCost($quoteItem->getCost()); if (!$this->hasQty()) { $this->setQty($quoteItem->getQty()); } $this->setQuoteItemImported(true); return $this; }
/** * Implementation of the validation logic * * @param Mage_Sales_Model_Quote_Item $item * @return bool */ public function validate($item) { $multipleNumber = $this->_helper->getMultipleQtyNumber(); $qty = $item->getQty(); //For example 100 % 10 if ($qty % $multipleNumber != 0) { return false; } return true; }
public function setQuoteItem(Mage_Sales_Model_Quote_Item $item) { $this->setQuoteItemId($item->getId()); $this->setQuoteId($item->getQuoteId()); $this->setProductId($item->getProductId()); $this->setStoreId($item->getStoreId()); $this->setQty($item->getQty()); $this->setIsActive(true); $expireDateTime = Mage::helper('zab_timedcart')->getExpireDatetime(now()); $this->setExpireDatetime($expireDateTime); return $this; }
/** * Validate stock of a quoteItem * * @param Mage_Sales_Model_Quote_Item $item * @param float $priceInclTax * @param float $priceExclTax * * @return ShopgateCartItem $result */ public function validateStock(Mage_Sales_Model_Quote_Item $item, $priceInclTax, $priceExclTax) { $product = $item->getProduct(); /** @var Mage_CatalogInventory_Model_Stock_Item $stockItem */ $stockItem = $product->getStockItem(); $errors = array(); $isBuyable = true; $qtyBuyable = null; foreach ($item->getChildren() as $childItem) { /** @var Mage_Catalog_Model_Product $childProduct */ $childProduct = $childItem->getProduct(); /** @var Mage_CatalogInventory_Model_Stock_Item $childStock */ $childStock = $childProduct->getStockItem(); if ($childStock->getManageStock() && !$childProduct->isSaleable() && !$childStock->getBackorders()) { $isBuyable = false; $error = array(); $error['type'] = ShopgateLibraryException::CART_ITEM_OUT_OF_STOCK; $error['message'] = ShopgateLibraryException::getMessageFor(ShopgateLibraryException::CART_ITEM_OUT_OF_STOCK); $errors[] = $error; } else { if ($childStock->getManageStock() && !$childStock->checkQty($childItem->getQty()) && !$childStock->getBackorders()) { $isBuyable = false; $error = array(); $error['type'] = ShopgateLibraryException::CART_ITEM_REQUESTED_QUANTITY_NOT_AVAILABLE; $error['message'] = ShopgateLibraryException::getMessageFor(ShopgateLibraryException::CART_ITEM_REQUESTED_QUANTITY_NOT_AVAILABLE); $errors[] = $error; if ($qtyBuyable == null || $qtyBuyable > $childStock->getQty()) { $qtyBuyable = $childStock->getQty(); } } else { if (Mage::helper('shopgate/config')->getIsMagentoVersionLower1410()) { $checkIncrements = Mage::helper('shopgate')->checkQtyIncrements($childStock, $childItem->getQty()); } else { $checkIncrements = $childStock->checkQtyIncrements($childItem->getQty()); } if ($childStock->getManageStock() && $checkIncrements->getHasError()) { $isBuyable = false; $error = array(); $error['type'] = ShopgateLibraryException::CART_ITEM_REQUESTED_QUANTITY_NOT_AVAILABLE; $error['message'] = ShopgateLibraryException::getMessageFor(ShopgateLibraryException::CART_ITEM_REQUESTED_QUANTITY_NOT_AVAILABLE); $errors[] = $error; $stockItem->setQty((int) ($item->getQtyToAdd() / $stockItem->getQtyIncrements()) * $stockItem->getQtyIncrements()); } } } } $qtyBuyable = $qtyBuyable == null ? (int) $item->getQty() : (int) $qtyBuyable; return Mage::helper('shopgate')->generateShopgateCartItem($product, $isBuyable, $qtyBuyable, $priceInclTax, $priceExclTax, $errors, (int) $stockItem->getQty()); }
/** * Use our own method to get buyRequest * @param Mage_Sales_Model_Quote_Item $salesItem * @return Varien_Object * */ public function getBuyRequest($salesItem, $option = false) { if ($option) { $option = $salesItem->getOptionByCode('info_buyRequest'); $buyRequest = new Varien_Object($option && $option->getValue() ? unserialize($option->getValue()) : null); $buyRequest->setOriginalQty($buyRequest->getQty())->setQty($salesItem->getQty() * 1); return $buyRequest; } $option = $salesItem->getProductOptionByCode('info_buyRequest'); if (!$option) { $option = array(); } $buyRequest = new Varien_Object($option); $buyRequest->setQty($salesItem->getQtyOrdered() * 1); return $buyRequest; }
/** * Check max amount after adding product to cart * * @param Mage_Sales_Model_Quote_Item $quoteItem */ public function checkProductmaxAmount($quoteItem) { $quoteStore = $quoteItem->getStore(); if ($this->isProductEnable($quoteStore)) { $maxAmount = $this->getCartMaxAmount($quoteStore); /* @var $quote Mage_Sales_Model_Quote */ $quote = $quoteItem->getQuote(); $grandTotal = $quote->getGrandTotal(); $_product = Mage::getModel('catalog/product')->load($quoteItem->getProduct()->getId()); $grandTotal += $_product->getFinalPrice($quoteItem->getQty()); if ($grandTotal > $maxAmount) { $formater = new Varien_Filter_Template(); $formater->setVariables(array('amount' => Mage::helper('core')->currency($maxAmount, true, false))); $format = $this->getProductMessage($quoteStore); // throw exception for "remove" product to cart Mage::throwException($formater->filter($format)); } } }
/** * Returns the item's original price that includes tax * * @param Mage_Sales_Model_Quote_Item $item * @return double */ public function displayOriginalPriceInclTax($item) { $tax = 0; if ($item->getTaxPercent()) { $tax = $item->getPrice() * ($item->getTaxPercent() / 100); } return $this->convertPrice($item->getPrice() + $tax / $item->getQty()); }
/** * Check Quote item qty. If qty is not enougth for order, error flag and message added to $quote item * * @param Mage_Sales_Model_Quote_Item $quoteItem */ protected function checkQuoteItemQty($quoteItem) { $qty = $quoteItem->getQty(); if (($options = $quoteItem->getQtyOptions()) && $qty > 0) { $qty = $quoteItem->getProduct()->getTypeInstance(true)->prepareQuoteItemQty($qty, $quoteItem->getProduct()); $quoteItem->setData('qty', $qty); foreach ($options as $option) { $optionQty = $qty * $option->getValue(); $increaseOptionQty = ($quoteItem->getQtyToAdd() ? $quoteItem->getQtyToAdd() : $qty) * $option->getValue(); $stockItem = $option->getProduct()->getStockItem(); /* @var $stockItem Mage_CatalogInventory_Model_Stock_Item */ if (!$stockItem instanceof Mage_CatalogInventory_Model_Stock_Item) { $quoteItem->setHasError(true)->setMessage('Stock item for Product in option is not valid'); return; } $result = $stockItem->checkQuoteItemQty($optionQty, $optionQty, $option->getValue()); if ($result->getHasError()) { $quoteItem->setHasError(true)->setMessage($result->getQuoteMessage()); } } } else { $stockItem = $quoteItem->getProduct()->getStockItem(); /* @var $stockItem Mage_CatalogInventory_Model_Stock_Item */ if (!$stockItem instanceof Mage_CatalogInventory_Model_Stock_Item) { Mage::throwException(Mage::helper('cataloginventory')->__('Stock item for Product is not valid')); } /** * When we work with subitem (as subproduct of bundle or configurable product) */ if ($quoteItem->getParentItem()) { $rowQty = $quoteItem->getParentItem()->getQty() * $qty; /** * we are using 0 because original qty was processed */ $qtyForCheck = 0; } else { $increaseQty = $quoteItem->getQtyToAdd() ? $quoteItem->getQtyToAdd() : $qty; $rowQty = $qty; $qtyForCheck = $qty; } $result = $stockItem->checkQuoteItemQty($rowQty, $qtyForCheck, $qty); if ($result->getHasError()) { $quoteItem->setHasError(true)->setMessage($result->getQuoteMessage()); } } }
/** * Add new product to registry * * @param int|Mage_Sales_Model_Quote_Item $itemToAdd * @param Varien_Object $request * @return Enterprise_GiftRegistry_Model_Item */ public function addItem($itemToAdd, $request = null) { if ($itemToAdd instanceof Mage_Sales_Model_Quote_Item) { $productId = $itemToAdd->getProductId(); $qty = $itemToAdd->getQty(); } else { $productId = $itemToAdd; $qty = $request && $request->getQty() ? $request->getQty() : 1; } $product = $this->getProduct($productId); if ($product->getTypeInstance(true)->hasRequiredOptions($product) && (!$request && !$itemToAdd instanceof Mage_Sales_Model_Quote_Item)) { throw new Mage_Core_Exception(null, self::EXCEPTION_CODE_HAS_REQUIRED_OPTIONS); } if ($itemToAdd instanceof Mage_Sales_Model_Quote_Item) { $cartCandidate = $itemToAdd->getProduct(); $cartCandidate->setCustomOptions($itemToAdd->getOptionsByCode()); $cartCandidates = array($cartCandidate); } else { if (!$request) { $request = new Varien_Object(); $request->setBundleOption(array()); //Bundle options mocking for compatibility } $cartCandidates = $product->getTypeInstance(true)->prepareForCart($request, $product); } if (is_string($cartCandidates)) { //prepare process has error, seems like we have bundle throw new Mage_Core_Exception($cartCandidates, self::EXCEPTION_CODE_HAS_REQUIRED_OPTIONS); } $item = Mage::getModel('enterprise_giftregistry/item'); $items = $item->getCollection()->addRegistryFilter($this->getId()); foreach ($cartCandidates as $currentCandidate) { if ($currentCandidate->getParentProductId()) { continue; } $alreadyExists = false; $productId = $currentCandidate->getId(); foreach ($items as $itemForCheck) { if ($itemForCheck->isRepresentProduct($currentCandidate)) { $alreadyExists = true; $matchedItem = $itemForCheck; break; } } $candidateQty = $currentCandidate->getCartQty(); if (!empty($candidateQty)) { $qty = $candidateQty; } if ($alreadyExists) { $matchedItem->setQty($matchedItem->getQty() + $qty)->save(); } else { $customOptions = $currentCandidate->getCustomOptions(); $item = Mage::getModel('enterprise_giftregistry/item'); $item->setEntityId($this->getId())->setProductId($productId)->setOptions($customOptions)->setQty($qty)->save(); } } return $item; }
/** * Adds giftwrapitems cost to request as item * * @param Mage_Sales_Model_Quote_Item $item * @return int|bool */ protected function _addGwItemsAmount($item) { if (!$item->getGwId()) { return false; } $lineNumber = $this->_getNewLineCode(); $storeId = $item->getQuote()->getStoreId(); //Add gift wrapping price(for individual items) $gwItemsAmount = $item->getGwBasePrice() * $item->getQty(); $line = $this->_getNewDocumentRequestLineObject(); $line->setLineCode($lineNumber); $gwItemsSku = $this->_getConfigHelper()->getGwItemsSku($storeId); $line->setItemCode($gwItemsSku ? $gwItemsSku : self::DEFAULT_GW_ITEMS_SKU); $line->setItemDescription(self::DEFAULT_GW_ITEMS_DESCRIPTION); $line->setAvalaraGoodsAndServicesType($this->_getGiftTaxClassCode($storeId)); $line->setNumberOfItems($item->getQty()); $line->setlineAmount($gwItemsAmount); $line->setDiscounted('false'); if ($this->_getTaxDataHelper()->priceIncludesTax($storeId)) { $line->setTaxIncluded('true'); } $this->_lines[$lineNumber] = $line; $this->_setLinesToRequest(); $this->_lineToLineId[$lineNumber] = $this->_getConfigHelper()->getGwItemsSku($storeId); $this->_productGiftPair[$lineNumber] = $item->getId(); return $lineNumber; }
/** * Adds giftwrapitems cost to request as item * * @param Mage_Sales_Model_Quote_Item $item * @return int|bool */ protected function _addGwItemsAmount($item) { if (!$item->getGwId()) { return false; } $lineNumber = count($this->_lines); $storeId = $item->getQuote()->getStoreId(); //Add gift wrapping price(for individual items) $gwItemsAmount = $item->getGwBasePrice() * $item->getQty(); $line = new Line(); $line->setNo($lineNumber); $gwItemsSku = $this->_getConfigHelper()->getGwItemsSku($storeId); $line->setItemCode($gwItemsSku ? $gwItemsSku : 'GwItemsAmount'); $line->setDescription('Gift Wrap Items Amount'); $line->setTaxCode($this->_getGiftTaxClassCode($storeId)); $line->setQty($item->getQty()); $line->setAmount($gwItemsAmount); $line->setDiscounted(false); if ($this->_getTaxDataHelper()->priceIncludesTax($storeId)) { $line->setTaxIncluded(true); } $this->_lines[$lineNumber] = $line; $this->_request->setLines($this->_lines); $this->_lineToLineId[$lineNumber] = $this->_getConfigHelper()->getGwItemsSku($storeId); $this->_productGiftPair[$lineNumber] = $item->getId(); return $lineNumber; }
/** * Retrieves the fixed weight set on the parent item * * @param Mage_Sales_Model_Quote_Item $item * @param bool $cartFreeShipping is the cart marked as free shipping * @param Webshopapps_Wsacommon_Model_Totals $finalTotals the final totals model instance * @param bool $isParent is the $item the parent item or a child * @return bool success */ private function setBundleParentWeight($item, $cartFreeShipping, &$finalTotals, $isParent = true) { $parentItem = $isParent ? $item : $item->getParentItem(); if ($parentItem->getProduct()->getWeightType()) { $itemWeight = $parentItem->getProduct()->getWeight(); $rowWeight = $itemWeight * $parentItem->getQty(); if ($cartFreeShipping || $item->getFreeShipping() === true) { $rowWeight = 0; } elseif (is_numeric($item->getFreeShipping())) { $freeQty = $item->getFreeShipping(); if ($item->getQty() > $freeQty) { $rowWeight = $itemWeight * ($item->getQty() - $freeQty); } else { $rowWeight = 0; } } $finalTotals->setWeight($rowWeight); $finalTotals->setFreeMethodWeight($rowWeight); return true; } else { return false; } }
/** * Checking quote item quantity * * @param Mage_Sales_Model_Quote_Item $item * @return Mage_CatalogInventory_Model_Stock_Item */ public function checkQuoteItemQty(Mage_Sales_Model_Quote_Item $item) { $qty = $item->getQty(); if (!is_numeric($qty)) { $qty = floatval($qty); } if (!$this->getIsInStock()) { $this->_addQuoteItemError($item, Mage::helper('cataloginventory')->__('This product is currently out of stock.'), Mage::helper('cataloginventory')->__('Some of the products are currently out of stock'), 'stock'); $item->setUseOldQty(true); return $this; } if ($this->getMinSaleQty() && $qty < $this->getMinSaleQty()) { $this->_addQuoteItemError($item, Mage::helper('cataloginventory')->__('The minimum quantity allowed for purchase is %s.', $this->getMinSaleQty() * 1), Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in the requested quantity'), 'qty'); return $this; } if ($this->getMaxSaleQty() && $qty > $this->getMaxSaleQty()) { $this->_addQuoteItemError($item, Mage::helper('cataloginventory')->__('The maximum quantity allowed for purchase is %s.', $this->getMaxSaleQty() * 1), Mage::helper('cataloginventory')->__('Some of the products can not be ordered in requested quantity'), 'qty'); return $this; } if ($this->checkQty($qty)) { if ($this->getQty() - $qty < 0 && $this->getBackorders() == Mage_CatalogInventory_Model_Stock::BACKORDERS_YES) { if ($this->getProduct()) { $item->setMessage(Mage::helper('cataloginventory')->__('This product is not available in the requested quantity. %s of the items will be backordered.', $this->getQty() > 0 ? ($qty - $this->getQty()) * 1 : $qty * 1, $this->getProduct()->getName())); } } } /** * Check quontity type */ if (!$this->getIsQtyDecimal()) { $qty = intval($qty); } $item->setHasError(false); /** * Adding stock data to quote item */ $item->addData(array('qty' => $qty, 'backorders' => $this->getBackorders())); return $this; }
/** * Retenders the item's redemption rules and final row total and returns it. * @param Mage_Sales_Model_Quote_Item $item * @return array a map of the new item redemption data: * array('redemptions_data'=>{...}, 'row_total'=>float) */ protected function getUpdatedRedemptionData($item, $do_incl_tax = true) { // Step 1: Create a map of usability for all applied redemptions //echo "$item->getRedeemedPointsHash()"; $redeemed_points = Mage::helper('rewards')->unhashIt($item->getRedeemedPointsHash()); // Prepare data from item and initalize counters if ($item->getQuote()) { $store_currency = round($item->getQuote()->getStoreToQuoteRate(), 4); } if ($item->getOrder()) { $store_currency = round($item->getOrder()->getStoreToQuoteRate(), 4); } if ($item->hasCustomPrice()) { $product_price = (double) $item->getCustomPrice() * $store_currency; } else { //@nelkaake -a 17/02/11: We need to use our own calculation because the one that was set by the // rest of the Magento system is rounded. if (Mage::helper('tax')->priceIncludesTax() && $item->getPriceInclTax()) { $product_price = $item->getPriceInclTax() / (1 + $item->getTaxPercent() / 100); } else { $product_price = (double) $item->getPrice() * $store_currency; } } if ($item->getParentItem() || sizeof($redeemed_points) == 0) { return array('redemptions_data' => array(), 'row_total_incl_tax' => $item->getRowTotalInclTax(), 'row_total' => $item->getRowTotal()); } $total_qty = $item->getQty(); $total_qty_redeemed = 0.0; $row_total = 0.0; $new_redeemed_points = array(); $ret = array(); // Loop through and apply all our rules. foreach ($redeemed_points as $key => &$redemption_instance) { $redemption_instance = (array) $redemption_instance; $applic_qty = $redemption_instance[self::POINTS_APPLICABLE_QTY]; $rule_id = $redemption_instance[self::POINTS_RULE_ID]; $effect = $redemption_instance[self::POINTS_EFFECT]; $uses = isset($redemption_instance[self::POINTS_USES]) ? (int) $redemption_instance[self::POINTS_USES] : 1; $rule = Mage::helper('rewards/rule')->getCatalogRule($rule_id); // If a rule was turned off at some point in the back-end it should be removed and not calculated in the cart anymore. if (!$rule->getIsActive()) { $this->removeCatalogRedemptionsFromItem($item, array($rule_id)); $effect = ""; } $total_qty_remain = $total_qty - $total_qty_redeemed; if ($total_qty_remain > 0) { if ($total_qty_remain < $applic_qty) { $applic_qty = $total_qty_remain; $redemption_instance[TBT_Rewards_Model_Redeem::POINTS_APPLICABLE_QTY] = $applic_qty; } $price_after_redem = $this->getPriceAfterEffect($product_price, $effect, $item); $row_total += $applic_qty * (double) $price_after_redem; $total_qty_redeemed += $applic_qty; $new_redeemed_points[] = $redemption_instance; } else { $redemption_instance[TBT_Rewards_Model_Catalogrule_Rule::POINTS_APPLICABLE_QTY] = 0; $redemption_instance[TBT_Rewards_Model_Catalogrule_Rule::POINTS_USES] = 1; // used once by default unset($redeemed_points[$key]); } } $ret['redemptions_data'] = $new_redeemed_points; // Add in the left over products that perhaps weren't affected by qty adjustment. $total_qty_remain = $total_qty - $total_qty_redeemed; if ($total_qty_remain < 0) { $total_qty_remain = 0; $total_qty_redeemed = $total_qty; //throw new Exception("Redemption rules may be overlapping. Please notify the store administrator of this error."); } $row_total += $total_qty_remain * (double) $product_price; $ret['row_total'] = $row_total; $ret['row_total_incl_tax'] = $row_total * (1 + $item->getTaxPercent() / 100); return $ret; }
/** * Assigns totals values using variables passed in by reference. * * @param Mage_Sales_Model_Quote_Item $item * @param int $weight * @param int $qty * @param int $price * @param $freeMethodWeight * @param bool $useParent * @param bool $ignoreFreeItems * @param array $itemGroup * @param bool $useDiscountValue * @param bool $cartFreeShipping * @param bool $useBase * @param bool $useTax * @param int $basePriceInclTax * @return bool */ public static function getItemInclFreeTotals($item, &$weight, &$qty, &$price, &$freeMethodWeight, $useParent = true, $ignoreFreeItems = true, &$itemGroup = array(), $useDiscountValue = false, $cartFreeShipping = false, $useBase = false, $useTax = false, &$basePriceInclTax = 0) { $adminOrder = false; /** * if order is placed in admin and we're using the sales_order event qty isn't set. * DIMSHIP-143 */ if ($item->getQtyOrdered() && !$item->getQty()) { $item->setQty($item->getQtyOrdered()); $adminOrder = true; } $totals = Mage::helper('wsacommon/totals')->getTotals($item, $useParent, $ignoreFreeItems, $cartFreeShipping); if ($adminOrder) { self::removeQty($item); } if (!$totals) { return false; } else { $weight = $totals->getWeight(); $qty = $totals->getQty(); if (!$useDiscountValue) { $useTax && !$useBase ? $price = $totals->getPriceInclTax() : false; $useTax && $useBase ? $price = $totals->getBasePriceInclTax() : false; !$useTax && !$useBase ? $price = $totals->getPrice() : false; !$useTax && $useBase ? $price = $totals->getBasePrice() : false; } else { $useTax && !$useBase ? $price = $totals->getDiscountedPriceInclTax() : false; $useTax && $useBase ? $price = $totals->getBaseDiscountedPriceInclTax() : false; !$useTax && !$useBase ? $price = $totals->getDiscountedPrice() : false; !$useTax && $useBase ? $price = $totals->getBaseDiscountedPrice() : false; } $freeMethodWeight = $totals->getFreeMethodWeight(); self::processItemGroup($itemGroup, $item); return true; } }
/** * Retrieve quote item product in stock flag * * @param Mage_Sales_Model_Quote_Item $item * @return bool */ public function getQuoteItemProductIsInStock($item) { if ($item->getProduct()->isSaleable()) { if ($item->getProduct()->getQty() >= $item->getQty()) { return true; } } return false; }
/** * Returns a total discount on the cart from the provided items * * @param Mage_Sales_Model_Quote_Item $item * @param Mage_Sales_Model_Quote_Address $address * @param TBT_Rewards_Model_Sales_Rule $rule * @param array() &$cartRules * @param int $qty max discount qty or unlimited if null * @return array($discountAmount, $baseDiscountAmount) */ protected function _getTotalPercentDiscountOnitem($item, $address, $rule, &$cartRules, $qty = null) { $quote = $item->getQuote(); $store = $item->getQuote()->getStore(); $qty = empty($qty) ? $item->getQty() : (int) $qty; $quoteAmount = $quote->getStore()->convertPrice($cartRules[$rule->getId()]); $quoteAmountBase = $cartRules[$rule->getId()]; if (Mage::helper('tax')->discountTax($store) && !Mage::helper('tax')->applyTaxAfterDiscount($store)) { $tax_amount = $item->getTaxAmount() / $item->getQty() * $qty; $base_tax_amount = $item->getBaseTaxAmount() / $item->getQty() * $qty; $quoteAmount += $tax_amount; // $cartItem->getTaxAmount(); $quoteAmountBase += $base_tax_amount; // $cartItem->getTaxAmount(); } else { $tax_amount = $base_tax_amount = 0; } $shipping_amount = $address->getShippingAmount(); $base_shipping_amount = $address->getBaseShippingAmount(); $add_shipping = $rule->getApplyToShipping() ? $shipping_amount : 0; $add_base_shipping = $rule->getApplyToShipping() ? $base_shipping_amount : 0; $discountAmount = min($item->getRowTotal() / $item->getQty() * $qty - $item->getDiscountAmount() + $add_shipping + $tax_amount, $quoteAmount); $baseDiscountAmount = min($item->getBaseRowTotal() / $item->getQty() * $qty - $item->getBaseDiscountAmount() + $add_base_shipping + $base_tax_amount, $quoteAmountBase); return array($discountAmount, $baseDiscountAmount); }
/** * Correct quantity list price calculations by cart item. * * Basically, calculate the price of the item's options (ie. item price - base * product price). * * @param array $list * @param Mage_Sales_Model_Quote_Item $item * @return array */ public function correctPriceCalculationsByCartItem(array $list, Mage_Sales_Model_Quote_Item $item) { if (count($list) && $item) { $qty = (double) $item->getQty(); $qtyKey = $this->getQtyKey($qty); $optionsPrice = null; $optionsPriceInclTax = null; // if we have applied an overriding price on the item we can run an easier calculation method, se the else block for that if (!$item->hasCustomPrice()) { /* @var Mage_Catalog_Model_Product_Type_Price $priceModel */ $priceModel = $this->getProductPriceModel($item->getProduct(), true); /* @var Mage_Catalog_Model_Product $product */ $product = Mage::getModel('catalog/product')->load($item->getProduct()->getId()); // calculate normal product price based on item quantity $productPrice = Mage::helper('core')->currency($priceModel->getFinalPrice($qty, $product), false, false); $productPriceInclTax = Mage::helper('tax')->getPrice($product, $productPrice, true, null, null, null, null, null, false); // calculate option prices (item price - product base price) $optionsPrice = $item->getConvertedPrice() - $productPrice; $optionsPriceInclTax = $item->getPriceInclTax() - $productPriceInclTax; } else { // just fetch the overriding price which has been used from the quantity option list // and calculate the options price as item price - overriding price, that's it. if (isset($list[$qtyKey]) && isset($list[$qtyKey]['p']) && isset($list[$qtyKey]['p']['pu'])) { $optionsPrice = $item->getConvertedPrice() - (double) $list[$qtyKey]['p']['pu']; } if (isset($list[$qtyKey]) && isset($list[$qtyKey]['p']) && isset($list[$qtyKey]['p']['iu'])) { $optionsPriceInclTax = $item->getPriceInclTax() - (double) $list[$qtyKey]['p']['iu']; } } // if there was an additional option based price on the item, add that additional price to all quantity options, correcting their initial calculations if (!is_null($optionsPrice) && $optionsPrice > 0) { foreach ($list as $key => $option) { $list[$key]['p']['p'] += $optionsPrice * $option['qty']; $list[$key]['p']['pu'] += $optionsPrice; if (isset($list[$key]['p']['o'])) { $list[$key]['p']['o'] += $optionsPrice * $option['qty']; $list[$key]['p']['ou'] += $optionsPrice; } if (isset($list[$key]['p']['e'])) { $list[$key]['p']['e'] += $optionsPrice * $option['qty']; $list[$key]['p']['eu'] += $optionsPrice; } if (isset($list[$key]['p']['i']) && !is_null($optionsPriceInclTax) && $optionsPriceInclTax > 0) { $list[$key]['p']['i'] += $optionsPriceInclTax * $option['qty']; $list[$key]['p']['iu'] += $optionsPriceInclTax; } } } } return $list; }