/** * Returns all valid shipping methods for current quote. * (based on provided delivery address) * * @param Mage_Checkout_Model_Cart $mageCart * @return array */ public function getShippingMethods($mageCart) { $methods = array(); /** @var Mage_Sales_Model_Quote_Address $shippingAddress */ $shippingAddress = $mageCart->getQuote()->getShippingAddress(); $shippingAddress->collectTotals(); $shippingAddress->collectShippingRates(); $calc = Mage::getSingleton('tax/calculation'); $rates = $calc->getRatesForAllProductTaxClasses($calc->getRateOriginRequest()); $taxClassIdShipping = Mage::helper('tax')->getShippingTaxClass(Mage::helper("shopgate/config")->getConfig()->getStoreViewId()); $taxRateShipping = $taxClassIdShipping ? $rates[$taxClassIdShipping] : $taxClassIdShipping; /** @var Mage_Sales_Model_Quote_Address_Rate $_rate */ foreach ($shippingAddress->getShippingRatesCollection() as $_rate) { if ($_rate instanceof Mage_Shipping_Model_Rate_Result_Error || strpos($_rate->getCode(), 'error') !== false || $_rate->getCarrierInstance() == false) { /* skip errors so they dont get processed as valid shipping rates without any cost */ ShopgateLogger::getInstance()->log("Skipping Shipping Rate because of Error Type: '" . $_rate->getCode() . "'", ShopgateLogger::LOGTYPE_DEBUG); continue; } $shippingAddress->setShippingMethod($_rate->getCode()); $shippingAddress->setCollectShippingRates(true); $shippingAddress->collectTotals(); $method = new ShopgateShippingMethod(); $method->setId($_rate->getCode()); $method->setTitle($_rate->getMethodTitle()); $method->setShippingGroup($_rate->getCarrier()); $method->setDescription($_rate->getMethodDescription() ? $_rate->getMethodDescription() : ''); $method->setSortOrder($_rate->getCarrierInstance()->getSortOrder()); $method->setAmount($shippingAddress->getBaseShippingAmount()); $method->setAmountWithTax($shippingAddress->getBaseShippingInclTax()); $method->setTaxClass($taxClassIdShipping); $method->setTaxPercent(number_format($taxRateShipping, 2)); $methods[] = $method; } return $methods; }
/** * create carriers * * @return mixed */ protected function _getCarriers() { $resultsCarrier = array(); $mobileCarrierUse = unserialize(base64_decode(Configuration::get('SG_MOBILE_CARRIER'))); if ($this->_deliveryAddress) { foreach (Carrier::getCarriersForOrder(Address::getZoneById($this->_deliveryAddress->id), $this->getPlugin()->getContext()->customer->getGroups(), $this->getPlugin()->getContext()->cart) as $carrier) { /** @var CarrierCore $carrierItem */ $carrierItem = new Carrier($carrier['id_carrier'], $this->getPlugin()->getContext()->language->id); $taxRulesGroup = new TaxRulesGroup($carrierItem->id_tax_rules_group); $resultCarrier = new ShopgateShippingMethod(); /** * check is defined as mobile carrier */ $idColumn = version_compare(_PS_VERSION_, '1.5.0.1', '>=') ? 'id_reference' : 'id_carrier'; if (is_array($mobileCarrierUse) && empty($mobileCarrierUse[$carrier[$idColumn]])) { continue; } $resultCarrier->setId($carrier['id_carrier']); $resultCarrier->setTitle($carrier['name']); $resultCarrier->setDescription($carrier['delay']); $resultCarrier->setSortOrder($carrier['position']); $resultCarrier->setAmount($carrier['price_tax_exc']); $resultCarrier->setAmountWithTax($carrier['price']); $resultCarrier->setTaxClass($taxRulesGroup->name); if (version_compare(_PS_VERSION_, '1.5.0', '<')) { $carrierTax = Tax::getCarrierTaxRate($carrierItem->id, $this->_deliveryAddress->id); } else { $carrierTax = $carrierItem->getTaxesRate($this->_deliveryAddress); } $resultCarrier->setTaxPercent($carrierTax); $resultCarrier->setInternalShippingInfo(serialize(array('carrierId' => $carrier['id_carrier']))); $resultsCarrier[] = $resultCarrier; } } return $resultsCarrier; }