/** * Recalculate row information for item based on children calculation * * @param Mage_Sales_Model_Quote_Item_Abstract $item * @return Mage_Tax_Model_Sales_Total_Quote_Subtotal */ protected function _recalculateParent(Mage_Sales_Model_Quote_Item_Abstract $item) { $price = 0; $basePrice = 0; $rowTotal = 0; $baseRowTotal = 0; $priceInclTax = 0; $basePriceInclTax = 0; $rowTotalInclTax = 0; $baseRowTotalInclTax = 0; foreach ($item->getChildren() as $child) { $price += $child->getPrice() * $child->getQty(); $basePrice += $child->getBasePrice() * $child->getQty(); $rowTotal += $child->getRowTotal(); $baseRowTotal += $child->getBaseRowTotal(); $priceInclTax += $child->getPriceInclTax() * $child->getQty(); $basePriceInclTax += $child->getBasePriceInclTax() * $child->getQty(); $rowTotalInclTax += $child->getRowTotalInclTax(); $baseRowTotalInclTax += $child->getBaseRowTotalInclTax(); } /** * * Customisation To make the custom price work with configurable items * **/ if ($item->getCustomPrice()) { $customPrice = $item->getCustomPrice(); $price = $customPrice; $basePrice = $customPrice; $rowTotal = $customPrice * $item->getQty(); $baseRowTotal = $customPrice * $item->getQty(); $priceInclTax = $customPrice; $basePriceInclTax = $customPrice; $rowTotalInclTax = $customPrice * $item->getQty(); $baseRowTotalInclTax = $customPrice * $item->getQty(); } $item->setConvertedPrice($price); $item->setPrice($basePrice); $item->setRowTotal($rowTotal); $item->setBaseRowTotal($baseRowTotal); $item->setPriceInclTax($priceInclTax); $item->setBasePriceInclTax($basePriceInclTax); $item->setRowTotalInclTax($rowTotalInclTax); $item->setBaseRowTotalInclTax($baseRowTotalInclTax); return $this; }
/** * Get an estimated delivery message for a quote item. * * @param Mage_Sales_Model_Quote_Item_Abstract * @return string */ public function getEddMessage(Mage_Sales_Model_Quote_Item_Abstract $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->getEddTemplate(), $singularOrPluralItem, $eddItem->getDeliveryWindowFromDate()->format('m/d/y'), $eddItem->getDeliveryWindowToDate()->format('m/d/y')) : ''; }
/** * Get the quantity requeted for a single item. * * @param Mage_Sales_Model_Quote_Item_Abstract * @return int */ public function getRequestedItemQuantity(Mage_Sales_Model_Quote_Item_Abstract $item) { // Child item quantity is the static quantity of the child // item within a single unit of the parent. E.g. a configurable // product's child item's quantity, will always be 1 - one child in // the configurable item. Bundle items, however, will be // the number of the child items in a single unit of the // parent bundle, depending on how the bundle was configured when // added to cart - actual quantity of the child is child // quantity * parent quantity. $parentItem = $item->getParentItem(); return $item->getQty() * ($parentItem ? $parentItem->getQty() : 1); }
/** * Return discount item qty * * @param Mage_Sales_Model_Quote_Item_Abstract $item * @param Mage_SalesRule_Model_Rule $rule * @return int */ protected function _getItemQty($item, $rule) { //@nelkaake: Magento 1.3 and lower doesnt have the item->getTotalQty attribute. if (Mage::helper('rewards/version')->isBaseMageVersionAtLeast('1.4')) { $qty = $item->getTotalQty(); } else { $qty = $item->getQty(); if ($item->getParentItem()) { $qty *= $item->getParentItem()->getQty(); } } return $rule->getDiscountQty() ? min($qty, $rule->getDiscountQty()) : $qty; }
/** * Request shipping rates for entire address or specified address item * Returns true if current selected shipping method code corresponds to one of the found rates * * @param Mage_Sales_Model_Quote_Item_Abstract $item * @return bool */ public function requestShippingRates(Mage_Sales_Model_Quote_Item_Abstract $item = null) { //Mage::log("requestShippingRates"); /** @var $request Mage_Shipping_Model_Rate_Request */ $request = Mage::getModel('shipping/rate_request'); $request->setAllItems($item ? array($item) : $this->getAllItems()); $request->setDestCountryId($this->getCountryId()); $request->setDestRegionId($this->getRegionId()); $request->setDestRegionCode($this->getRegionCode()); /** * need to call getStreet with -1 * to get data in string instead of array */ $request->setDestStreet($this->getStreet(-1)); $request->setDestCity($this->getCity()); $request->setDestPostcode($this->getPostcode()); $request->setPackageValue($item ? $item->getBaseRowTotal() : $this->getBaseSubtotal()); $packageValueWithDiscount = $item ? $item->getBaseRowTotal() - $item->getBaseDiscountAmount() : $this->getBaseSubtotalWithDiscount(); $request->setPackageValueWithDiscount($packageValueWithDiscount); $request->setPackageWeight($item ? $item->getRowWeight() : $this->getWeight()); $request->setPackageQty($item ? $item->getQty() : $this->getItemQty()); /** * Need for shipping methods that use insurance based on price of physical products */ $packagePhysicalValue = $item ? $item->getBaseRowTotal() : $this->getBaseSubtotal() - $this->getBaseVirtualAmount(); $request->setPackagePhysicalValue($packagePhysicalValue); $request->setFreeMethodWeight($item ? 0 : $this->getFreeMethodWeight()); /** * Store and website identifiers need specify from quote */ /*$request->setStoreId(Mage::app()->getStore()->getId()); $request->setWebsiteId(Mage::app()->getStore()->getWebsiteId());*/ $request->setStoreId($this->getQuote()->getStore()->getId()); $request->setWebsiteId($this->getQuote()->getStore()->getWebsiteId()); $request->setFreeShipping($this->getFreeShipping()); /** * Currencies need to convert in free shipping */ $request->setBaseCurrency($this->getQuote()->getStore()->getBaseCurrency()); $request->setPackageCurrency($this->getQuote()->getStore()->getCurrentCurrency()); $request->setLimitCarrier($this->getLimitCarrier()); $result = Mage::getModel('shipping/shipping')->collectRatesWithAddress($request, $this)->getResult(); $found = false; if ($result) { $shippingRates = $result->getAllRates(); foreach ($shippingRates as $shippingRate) { $rate = Mage::getModel('sales/quote_address_rate')->importShippingRate($shippingRate); if (!$item) { $this->addShippingRate($rate); } if ($this->getShippingMethod() == $rate->getCode()) { if ($item) { $item->setBaseShippingAmount($rate->getPrice()); } else { /** * possible bug: this should be setBaseShippingAmount(), * see Mage_Sales_Model_Quote_Address_Total_Shipping::collect() * where this value is set again from the current specified rate price * (looks like a workaround for this bug) */ $this->setShippingAmount($rate->getPrice()); } $found = true; } } } return $found; }
/** * Inject general item data into the order item payload. * * @return self */ protected function _injectItemData() { $this->_orderItem->setLineNumber($this->_item->getId())->setItemId($this->_item->getSku())->setQuantity((int) $this->_item->getQty())->setDescription($this->_item->getName())->setHtsCode($this->_taxHelper->getProductHtsCodeByCountry($this->_itemProduct, $this->_address->getCountryId()))->setManufacturingCountryCode($this->_itemProduct->getCountryOfManufacture()); return $this; }
/** * When an item has no stock in ROM and is set to backorderable in Magento, then return true, * otherwise return false as this item is not backorderable it is simply out of stock in ROM. * * @param Mage_Sales_Model_Quote_Item_Abstract * @param int * @return bool */ protected function isItemBackorderable(Mage_Sales_Model_Quote_Item_Abstract $quoteItem, $romAvailableQuantity) { return $romAvailableQuantity <= $quoteItem->getQty() && $this->getItemProductStockItem($quoteItem)->getBackorders() > Mage_CatalogInventory_Model_Stock::BACKORDERS_NO; }
/** * Recalculate row information for item based on children calculation * * @param Mage_Sales_Model_Quote_Item_Abstract $item * * @return Mage_Tax_Model_Sales_Total_Quote_Subtotal */ protected function _recalculateParent(Mage_Sales_Model_Quote_Item_Abstract $item) { $rowTotal = 0; $baseRowTotal = 0; $rowTotalInclTax = 0; $baseRowTotalInclTax = 0; $rowTax = 0; $baseRowTax = 0; $store = $item->getStore(); $qty = $item->getQty(); foreach ($item->getChildren() as $child) { $rowTotal += $child->getRowTotal(); $baseRowTotal += $child->getBaseRowTotal(); $rowTotalInclTax += $child->getRowTotalInclTax(); $baseRowTotalInclTax += $child->getBaseRowTotalInclTax(); $rowTax += $child->getRowTax(); $baseRowTax += $child->getBaseRowTax(); } $item->setConvertedPrice($store->roundPrice($rowTotal) / $qty); $item->setPrice($store->roundPrice($baseRowTotal) / $qty); $item->setRowTotal($rowTotal); $item->setBaseRowTotal($baseRowTotal); $item->setPriceInclTax($store->roundPrice($rowTotalInclTax) / $qty); $item->setBasePriceInclTax($store->roundPrice($baseRowTotalInclTax) / $qty); $item->setRowTotalInclTax($rowTotalInclTax); $item->setBaseRowTotalInclTax($baseRowTotalInclTax); $item->setRowTax($rowTax); $item->setBaseRowTax($baseRowTax); return $this; }
/** * Request shipping rates for entire address or specified address item * Returns true if current selected shipping method code corresponds to one of the found rates * * @param Mage_Sales_Model_Quote_Item_Abstract $item * @return bool */ public function requestShippingRates(Mage_Sales_Model_Quote_Item_Abstract $item = null) { /** @var $request Mage_Shipping_Model_Rate_Request */ $request = Mage::getModel('shipping/rate_request'); $request->setAllItems($item ? array($item) : $this->getAllItems()); $request->setDestCountryId($this->getCountryId()); $request->setDestRegionId($this->getRegionId()); $request->setDestRegionCode($this->getRegionCode()); /** * need to call getStreet with -1 * to get data in string instead of array */ $request->setDestStreet($this->getStreet(-1)); $request->setDestCity($this->getCity()); $request->setDestPostcode($this->getPostcode()); $request->setPackageValue($item ? $item->getBaseRowTotal() : $this->getBaseSubtotal()); $packageValueWithDiscount = $item ? $item->getBaseRowTotal() - $item->getBaseDiscountAmount() : $this->getBaseSubtotalWithDiscount(); $request->setPackageValueWithDiscount($packageValueWithDiscount); $request->setPackageWeight($item ? $item->getRowWeight() : $this->getWeight()); $request->setPackageQty($item ? $item->getQty() : $this->getItemQty()); /** * Need for shipping methods that use insurance based on price of physical products */ $packagePhysicalValue = $item ? $item->getBaseRowTotal() : $this->getBaseSubtotal() - $this->getBaseVirtualAmount(); $request->setPackagePhysicalValue($packagePhysicalValue); $request->setFreeMethodWeight($item ? 0 : $this->getFreeMethodWeight()); /** * Store and website identifiers need specify from quote */ /*$request->setStoreId(Mage::app()->getStore()->getId()); $request->setWebsiteId(Mage::app()->getStore()->getWebsiteId());*/ $request->setStoreId($this->getQuote()->getStore()->getId()); $request->setWebsiteId($this->getQuote()->getStore()->getWebsiteId()); $request->setFreeShipping($this->getFreeShipping()); /** * Currencies need to convert in free shipping */ $request->setBaseCurrency($this->getQuote()->getStore()->getBaseCurrency()); $request->setPackageCurrency($this->getQuote()->getStore()->getCurrentCurrency()); $request->setLimitCarrier($this->getLimitCarrier()); $request->setBaseSubtotalInclTax($this->getBaseSubtotalInclTax()); $result = Mage::getModel('shipping/shipping')->collectRates($request)->getResult(); $found = false; if ($result) { $shippingRates = $result->getAllRates(); // ============ Apply shipping on order minimum value after discount specific to coupon code only ================= if (!Mage::app()->getStore()->isAdmin()) { foreach ($shippingRates as $i => $r) { if ($r->getMethod() == 'freeshipping') { unset($shippingRates[$i]); } } } $isfree = true; $minimum_purchange_amount = Mage::getStoreConfig('sales/minimum_order_custom/minimum_purchange_amount'); $minimum_purchange_amount_status = Mage::getStoreConfig('sales/minimum_order_custom/minimum_purchange_amount_status'); if ($minimum_purchange_amount_status == '1' && $minimum_purchange_amount > 0) { $minPurchaseAmt = Mage::helper('common')->checkMinPurchageAmount($minimum_purchange_amount); if ($minPurchaseAmt) { foreach ($shippingRates as $i => $r) { if ($r->getMethod() == 'standard') { $shippingRates[$i]->setPrice(0); $shippingRates[$i]->setCost(0); $isfree = true; } } } } // ========================================================================================== foreach ($shippingRates as $shippingRate) { $rate = Mage::getModel('sales/quote_address_rate')->importShippingRate($shippingRate); if (!$item) { $this->addShippingRate($rate); } if ($this->getShippingMethod() == $rate->getCode()) { if ($item) { $item->setBaseShippingAmount($rate->getPrice()); } else { /** * possible bug: this should be setBaseShippingAmount(), * see Mage_Sales_Model_Quote_Address_Total_Shipping::collect() * where this value is set again from the current specified rate price * (looks like a workaround for this bug) */ $this->setShippingAmount($rate->getPrice()); } $found = true; } } } return $found; }
/** * Process item fixed taxes * * @deprecated since 1.3.2.3 * @param Mage_Sales_Model_Quote_Address $address * @param Mage_Sales_Model_Quote_Item_Abstract $item * @param bool $updateParent * @return Mage_Weee_Model_Total_Quote_Weee */ protected function _processItem(Mage_Sales_Model_Quote_Address $address, $item, $updateParent = false) { $store = $address->getQuote()->getStore(); if (!$this->_helper->isEnabled($store)) { return $this; } $custTaxClassId = $address->getQuote()->getCustomerTaxClassId(); $taxCalculationModel = Mage::getSingleton('tax/calculation'); /* @var $taxCalculationModel Mage_Tax_Model_Calculation */ $request = $taxCalculationModel->getRateRequest($address, $address->getQuote()->getBillingAddress(), $custTaxClassId, $store); $defaultRateRequest = $taxCalculationModel->getRateRequest(false, false, false, $store); $attributes = $this->_helper->getProductWeeeAttributes($item->getProduct(), $address, $address->getQuote()->getBillingAddress(), $store->getWebsiteId()); $applied = array(); $productTaxes = array(); foreach ($attributes as $k => $attribute) { $baseValue = $attribute->getAmount(); $value = $store->convertPrice($baseValue); $rowValue = $value * $item->getQty(); $baseRowValue = $baseValue * $item->getQty(); $title = $attribute->getName(); /** * Apply discount to fixed tax */ if ($item->getDiscountPercent() && $this->_helper->isDiscounted($store)) { $valueDiscount = $value / 100 * $item->getDiscountPercent(); $baseValueDiscount = $baseValue / 100 * $item->getDiscountPercent(); $rowValueDiscount = $rowValue / 100 * $item->getDiscountPercent(); $baseRowValueDiscount = $baseRowValue / 100 * $item->getDiscountPercent(); $address->setDiscountAmount($address->getDiscountAmount() + $rowValueDiscount); $address->setBaseDiscountAmount($address->getBaseDiscountAmount() + $baseRowValueDiscount); $address->setGrandTotal($address->getGrandTotal() - $rowValueDiscount); $address->setBaseGrandTotal($address->getBaseGrandTotal() - $baseRowValueDiscount); } $oneDisposition = $baseOneDisposition = $disposition = $baseDisposition = 0; /** * Apply tax percent to fixed tax */ if ($this->_helper->isTaxable($store)) { $currentPercent = $item->getTaxPercent(); $defaultPercent = $taxCalculationModel->getRate($defaultRateRequest->setProductClassId($item->getProduct()->getTaxClassId())); $valueBeforeVAT = $rowValue; $baseValueBeforeVAT = $baseRowValue; $oneDisposition = $store->roundPrice($value / (100 + $defaultPercent) * $currentPercent); $baseOneDisposition = $store->roundPrice($baseValue / (100 + $defaultPercent) * $currentPercent); $disposition = $store->roundPrice($rowValue / (100 + $defaultPercent) * $currentPercent); $baseDisposition = $store->roundPrice($baseRowValue / (100 + $defaultPercent) * $currentPercent); $item->setBaseTaxAmount($item->getBaseTaxAmount() + $baseDisposition); $item->setTaxAmount($item->getTaxAmount() + $disposition); $value -= $oneDisposition; $baseValue -= $baseOneDisposition; $rowValue -= $baseDisposition; $baseRowValue -= $disposition; $item->setWeeeTaxDisposition($item->getWeeeTaxDisposition() + $oneDisposition); $item->setBaseWeeeTaxDisposition($item->getBaseWeeeTaxDisposition() + $baseOneDisposition); $item->setWeeeTaxRowDisposition($item->getWeeeTaxRowDisposition() + $disposition); $item->setBaseWeeeTaxRowDisposition($item->getBaseWeeeTaxRowDisposition() + $baseDisposition); // $item->setTaxBeforeDiscount($item->getTaxBeforeDiscount() + $disposition); // $item->setBaseTaxBeforeDiscount($item->getBaseTaxBeforeDiscount() + $baseDisposition); $address->setTaxAmount($address->getTaxAmount() + $disposition); $address->setBaseTaxAmount($address->getBaseTaxAmount() + $baseDisposition); $rate = $taxCalculationModel->getRate($request->setProductClassId($item->getProduct()->getTaxClassId())); $this->_saveAppliedTaxes($address, $taxCalculationModel->getAppliedRates($request), $store->roundPrice($valueBeforeVAT - $rowValue), $store->roundPrice($baseValueBeforeVAT - $baseRowValue), $rate); $address->setGrandTotal($address->getGrandTotal() + $store->roundPrice($valueBeforeVAT - $rowValue)); $address->setBaseGrandTotal($address->getBaseGrandTotal() + $store->roundPrice($baseValueBeforeVAT - $baseRowValue)); } /** * Check if need include fixed tax amount to subtotal */ if ($this->_helper->includeInSubtotal($store)) { $address->setSubtotal($address->getSubtotal() + $rowValue); $address->setBaseSubtotal($address->getBaseSubtotal() + $baseRowValue); // $address->setSubtotalWithDiscount($address->getSubtotalWithDiscount() + $rowValue); // $address->setBaseSubtotalWithDiscount($address->getBaseSubtotalWithDiscount() + $baseRowValue); } else { $address->setTaxAmount($address->getTaxAmount() + $rowValue); $address->setBaseTaxAmount($address->getBaseTaxAmount() + $baseRowValue); } $productTaxes[] = array('title' => $title, 'base_amount' => $baseValue, 'amount' => $value, 'row_amount' => $rowValue, 'base_row_amount' => $baseRowValue, 'base_amount_incl_tax' => $baseValue + $baseOneDisposition, 'amount_incl_tax' => $value + $oneDisposition, 'row_amount_incl_tax' => $rowValue + $disposition, 'base_row_amount_incl_tax' => $baseRowValue + $baseDisposition); $applied[] = array('id' => $attribute->getCode(), 'percent' => null, 'hidden' => $this->_helper->includeInSubtotal($store), 'rates' => array(array('amount' => $rowValue, 'base_amount' => $baseRowValue, 'base_real_amount' => $baseRowValue, 'code' => $attribute->getCode(), 'title' => $title, 'percent' => null, 'position' => 1, 'priority' => -1000 + $k))); $item->setBaseWeeeTaxAppliedAmount($item->getBaseWeeeTaxAppliedAmount() + $baseValue); $item->setBaseWeeeTaxAppliedRowAmount($item->getBaseWeeeTaxAppliedRowAmount() + $baseRowValue); $item->setWeeeTaxAppliedAmount($item->getWeeeTaxAppliedAmount() + $value); $item->setWeeeTaxAppliedRowAmount($item->getWeeeTaxAppliedRowAmount() + $rowValue); } $this->_helper->setApplied($item, array_merge($this->_helper->getApplied($item), $productTaxes)); if ($updateParent) { $parent = $item->getParentItem(); $parent->setBaseWeeeTaxDisposition($parent->getBaseWeeeTaxDisposition() + $item->getBaseWeeeTaxDisposition()); $parent->setWeeeTaxDisposition($parent->getWeeeTaxDisposition() + $item->getWeeeTaxDisposition()); $parent->setBaseWeeeTaxRowDisposition($parent->getBaseWeeeTaxRowDisposition() + $item->getBaseWeeeTaxRowDisposition()); $parent->setWeeeTaxRowDisposition($parent->getWeeeTaxRowDisposition() + $item->getWeeeTaxRowDisposition()); $parent->setBaseWeeeTaxAppliedAmount($parent->getBaseWeeeTaxAppliedAmount() + $item->getBaseWeeeTaxAppliedAmount()); $parent->setBaseWeeeTaxAppliedRowAmount($parent->getBaseWeeeTaxAppliedRowAmount() + $item->getBaseWeeeTaxAppliedRowAmount()); $parent->setWeeeTaxAppliedAmount($parent->getWeeeTaxAppliedAmount() + $item->getWeeeTaxAppliedAmount()); $parent->setWeeeTaxAppliedRowAmount($parent->getWeeeTaxAppliedRowAmount() + $item->getWeeeTaxAppliedRowAmount()); } if ($applied) { $this->_saveAppliedTaxes($address, $applied, $item->getWeeeTaxAppliedAmount(), $item->getBaseWeeeTaxAppliedAmount(), null); } }
/** * Notify the customer if the quote item is backorderable with setting to notify customer. * * @param Mage_Sales_Model_Quote_Item_Abstract * @return self */ protected function _notifyCustomerIfItemBackorderable(Mage_Sales_Model_Quote_Item_Abstract $quoteItem) { /** @var Mage_CatalogInventory_Model_Stock_Item $stockItem */ $stockItem = $quoteItem->getProduct()->getStockItem(); if ((int) $stockItem->getBackorders() === Mage_CatalogInventory_Model_Stock::BACKORDERS_YES_NOTIFY) { /** @var float */ $qty = $quoteItem->getQty(); /** @var float */ $rowQty = $this->_calculateTotalQuantityRequested($quoteItem); /** @var Varien_Object */ $result = $stockItem->checkQuoteItemQty($rowQty, $qty); if (!is_null($result->getMessage())) { $quoteItem->setMessage($result->getMessage()); } if (!is_null($result->getItemBackorders())) { $quoteItem->setBackorders($result->getItemBackorders()); } } return $this; }
/** * WE NEEDED TO OVERRIDE THIS METHOD CALL TO UPDATE THE SHIPPING RATES AS * SOON AS WE RECEIVED THEM * * * * * Request shipping rates for entire address or specified address item * Returns true if current selected shipping method code corresponds to one of the found rates * * @param Mage_Sales_Model_Quote_Item_Abstract $item * @return bool */ public function requestShippingRates(Mage_Sales_Model_Quote_Item_Abstract $item = null) { /** * CUSTOMIZED THIS FUNCTION BY ADDING THIS EVENT CALL */ if (!$this->getQuote()->getShippingAddress()->getResidentialIndicator()) { Mage::dispatchEvent('widgetized_validate_address', array($this->_eventObject => $this, 'order' => $this->getQuote())); } /** @var $request Mage_Shipping_Model_Rate_Request */ $request = Mage::getModel('shipping/rate_request'); $request->setQuote($this->getQuote()); $request->setAllItems($item ? array($item) : $this->getAllItems()); $request->setDestCountryId($this->getCountryId()); $request->setDestRegionId($this->getRegionId()); $request->setDestRegionCode($this->getRegionCode()); /** * need to call getStreet with -1 * to get data in string instead of array */ $request->setDestStreet($this->getStreet(self::DEFAULT_DEST_STREET)); $request->setDestCity($this->getCity()); $request->setDestPostcode($this->getPostcode()); $request->setPackageValue($item ? $item->getBaseRowTotal() : $this->getBaseSubtotal()); $packageValueWithDiscount = $item ? $item->getBaseRowTotal() - $item->getBaseDiscountAmount() : $this->getBaseSubtotalWithDiscount(); $request->setPackageValueWithDiscount($packageValueWithDiscount); $request->setPackageWeight($item ? $item->getRowWeight() : $this->getWeight()); $request->setPackageQty($item ? $item->getQty() : $this->getItemQty()); /** * Need for shipping methods that use insurance based on price of physical products */ $packagePhysicalValue = $item ? $item->getBaseRowTotal() : $this->getBaseSubtotal() - $this->getBaseVirtualAmount(); $request->setPackagePhysicalValue($packagePhysicalValue); $request->setFreeMethodWeight($item ? 0 : $this->getFreeMethodWeight()); /** * Store and website identifiers need specify from quote */ /*$request->setStoreId(Mage::app()->getStore()->getId()); $request->setWebsiteId(Mage::app()->getStore()->getWebsiteId());*/ $request->setStoreId($this->getQuote()->getStore()->getId()); $request->setWebsiteId($this->getQuote()->getStore()->getWebsiteId()); $request->setFreeShipping($this->getFreeShipping()); /** * Currencies need to convert in free shipping */ $request->setBaseCurrency($this->getQuote()->getStore()->getBaseCurrency()); $request->setPackageCurrency($this->getQuote()->getStore()->getCurrentCurrency()); $request->setLimitCarrier($this->getLimitCarrier()); $request->setBaseSubtotalInclTax($this->getBaseSubtotalInclTax() + $this->getBaseExtraTaxAmount()); $result = Mage::getModel('shipping/shipping')->collectRates($request)->getResult(); $found = false; if ($result) { $shippingRates = $result->getAllRates(); // var_dump($shippingRates);die; /** * CUSTOMIZED THIS FUNCTION BY ADDING THIS EVENT CALL */ Mage::dispatchEvent($this->_eventPrefix . '_update_shipping_rates', array($this->_eventObject => $this, 'shipping_rates' => $shippingRates)); foreach ($shippingRates as $shippingRate) { $rate = Mage::getModel('sales/quote_address_rate')->importShippingRate($shippingRate); /** * COST is Cheaper than the PRICE * * We don't want to use the price, we want to give shipping * to users at cost. */ if (!$item) { $this->addShippingRate($rate); } if ($this->getShippingMethod() == $rate->getCode()) { $price = $rate->getCost(); if (!$price) { $price = $rate->getPrice(); } if ($item) { $item->setBaseShippingAmount($price); } else { /** * possible bug: this should be setBaseShippingAmount(), * see Mage_Sales_Model_Quote_Address_Total_Shipping::collect() * where this value is set again from the current specified rate price * (looks like a workaround for this bug) */ $this->setShippingAmount($price); } $found = true; } } } return $found; }
/** * Request shipping rates for entire address or specified address item * Returns true if current selected shipping method code corresponds to one of the found rates * * @param Mage_Sales_Model_Quote_Item_Abstract $item * @return bool */ public function requestShippingRates(Mage_Sales_Model_Quote_Item_Abstract $item = null) { /** @var $request Mage_Shipping_Model_Rate_Request */ $request = Mage::getModel('shipping/rate_request'); $request->setAllItems($item ? array($item) : $this->getAllItems()); $request->setDestCountryId($this->getCountryId()); $request->setDestRegionId($this->getRegionId()); $request->setDestRegionCode($this->getRegionCode()); /** * need to call getStreet with -1 * to get data in string instead of array */ $request->setDestStreet($this->getStreet(-1)); $request->setDestCity($this->getCity()); $request->setDestPostcode($this->getPostcode()); $request->setPackageValue($item ? $item->getBaseRowTotal() : $this->getBaseSubtotal()); $packageValueWithDiscount = $item ? $item->getBaseRowTotal() - $item->getBaseDiscountAmount() : $this->getBaseSubtotalWithDiscount(); $request->setPackageValueWithDiscount($packageValueWithDiscount); $request->setPackageWeight($item ? $item->getRowWeight() : $this->getWeight()); $request->setPackageQty($item ? $item->getQty() : $this->getItemQty()); /** * Need for shipping methods that use insurance based on price of physical products */ $packagePhysicalValue = $item ? $item->getBaseRowTotal() : $this->getBaseSubtotal() - $this->getBaseVirtualAmount(); $request->setPackagePhysicalValue($packagePhysicalValue); $request->setFreeMethodWeight($item ? 0 : $this->getFreeMethodWeight()); /** * Store and website identifiers need specify from quote */ /*$request->setStoreId(Mage::app()->getStore()->getId()); $request->setWebsiteId(Mage::app()->getStore()->getWebsiteId());*/ $request->setStoreId($this->getQuote()->getStore()->getId()); $request->setWebsiteId($this->getQuote()->getStore()->getWebsiteId()); $request->setFreeShipping($this->getFreeShipping()); /** * Currencies need to convert in free shipping */ $request->setBaseCurrency($this->getQuote()->getStore()->getBaseCurrency()); $request->setPackageCurrency($this->getQuote()->getStore()->getCurrentCurrency()); $request->setLimitCarrier($this->getLimitCarrier()); $request->setBaseSubtotalInclTax($this->getBaseSubtotalInclTax()); $result = Mage::getModel('shipping/shipping')->collectRates($request)->getResult(); $found = true; return $found; }
/** * Convert quote item to order item * * @param Mage_Sales_Model_Quote_Item_Abstract $item * @return Mage_Sales_Model_Order_Item */ public function itemToOrderItem(Mage_Sales_Model_Quote_Item_Abstract $item) { $orderItem = Mage::getModel('sales/order_item')->setStoreId($item->getStoreId())->setQuoteItemId($item->getId())->setProductId($item->getProductId())->setSuperProductId($item->getSuperProductId())->setParentProductId($item->getParentProductId())->setSku($item->getSku())->setName($item->getName())->setDescription($item->getDescription())->setWeight($item->getWeight())->setIsQtyDecimal($item->getIsQtyDecimal())->setQtyOrdered($item->getQty())->setOriginalPrice($item->getOriginalPrice())->setAppliedRuleIds($item->getAppliedRuleIds())->setAdditionalData($item->getAdditionalData())->setPrice($item->getCalculationPrice())->setTaxPercent($item->getTaxPercent())->setTaxAmount($item->getTaxAmount())->setRowWeight($item->getRowWeight())->setRowTotal($item->getRowTotal())->setBasePrice($item->getBaseCalculationPrice())->setBaseOriginalPrice($item->getPrice())->setBaseTaxAmount($item->getBaseTaxAmount())->setBaseRowTotal($item->getBaseRowTotal()); if (!$item->getNoDiscount()) { $orderItem->setDiscountPercent($item->getDiscountPercent())->setDiscountAmount($item->getDiscountAmount())->setBaseDiscountAmount($item->getBaseDiscountAmount()); } Mage::dispatchEvent('sales_convert_quote_item_to_order_item', array('order_item' => $orderItem, 'item' => $item)); return $orderItem; }