本文整理汇总了PHP中Mage_Shipping_Model_Rate_Request::getFreeShipping方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Shipping_Model_Rate_Request::getFreeShipping方法的具体用法?PHP Mage_Shipping_Model_Rate_Request::getFreeShipping怎么用?PHP Mage_Shipping_Model_Rate_Request::getFreeShipping使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Shipping_Model_Rate_Request
的用法示例。
在下文中一共展示了Mage_Shipping_Model_Rate_Request::getFreeShipping方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: collectRates
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
$result = Mage::getModel('shipping/rate_result');
/* @var $result Mage_Shipping_Model_Rate_Result */
$result->append($this->_getStandardShippingRate());
$expressWeightThreshold = $this->getConfigData('express_weight_threshold');
$eligibleForExpressDelivery = true;
foreach ($request->getAllItems() as $_item) {
if ($_item->getWeight() > $expressWeightThreshold) {
$eligibleForExpressDelivery = false;
}
}
if ($eligibleForExpressDelivery) {
$result->append($this->_getExpressShippingRate());
}
if ($request->getFreeShipping()) {
/**
* If the request has the free shipping flag,
* append a free shipping rate to the result.
*/
$freeShippingRate = $this->_getFreeShippingRate();
$result->append($freeShippingRate);
}
return $result;
}
示例2: collectRates
/**
* Enter description here...
*
* @param Mage_Shipping_Model_Rate_Request $data
* @return Mage_Shipping_Model_Rate_Result
*/
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!$this->getConfigFlag('active')) {
return false;
}
$freeBoxes = 0;
if ($request->getAllItems()) {
foreach ($request->getAllItems() as $item) {
if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
continue;
}
if ($item->getHasChildren() && $item->isShipSeparately()) {
foreach ($item->getChildren() as $child) {
if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
$freeBoxes += $item->getQty() * $child->getQty();
}
}
} elseif ($item->getFreeShipping()) {
$freeBoxes += $item->getQty();
}
}
}
$this->setFreeBoxes($freeBoxes);
$result = Mage::getModel('shipping/rate_result');
if ($this->getConfigData('type') == 'O') {
// per order
$shippingPrice = $this->getConfigData('price');
} elseif ($this->getConfigData('type') == 'I') {
// per item
$shippingPrice = $request->getPackageQty() * $this->getConfigData('price') - $this->getFreeBoxes() * $this->getConfigData('price');
} else {
$shippingPrice = false;
}
$shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice);
if ($shippingPrice !== false) {
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier('zabstorepickup');
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod('storepickup');
$method->setMethodTitle($this->getConfigData('name'));
if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
$shippingPrice = '0.00';
}
$method->setPrice($shippingPrice);
$method->setCost($shippingPrice);
$address = $this->getAddress();
$additional = false;
if ($address) {
/**@var $address Mage_Customer_Model_Address**/
$address = $address->format('html');
$additional = Mage::helper('zab_storepickup')->__("Pickup in:") . "<br/>" . "<address>{$address}</address><br/>";
}
if ($this->getConfigData('instruction')) {
$additional .= $this->getConfigData('instruction');
}
$method->setAdditionalInfo($additional);
$result->append($method);
}
return $result;
}
示例3: collectRates
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!$this->getConfigFlag('active')) {
return false;
}
$freeBoxes = 0;
if ($request->getAllItems()) {
foreach ($request->getAllItems() as $item) {
if ($item->getFreeShipping() && !$item->getProduct()->isVirtual()) {
$freeBoxes += $item->getQty();
}
}
}
$this->setFreeBoxes($freeBoxes);
$quoteId = Mage::getSingleton('core/session')->proposal_quote_id;
if ($quoteId) {
$price = Mage::app()->getHelper('qquoteadv')->getQquoteShipPriceById($quoteId);
$result = Mage::getModel('shipping/rate_result');
/* if ($this->getConfigData('type') == 'O') { // per order
$shippingPrice = $price;
} elseif ($this->getConfigData('type') == 'I') { // per item
$shippingPrice = ($request->getPackageQty() * $price) - ($this->getFreeBoxes() * $price);
} else {
$shippingPrice = false;
}*/
$type = Mage::app()->getHelper('qquoteadv')->getShipTypeByQuote();
if ($type == 'O') {
// per order
$shippingPrice = $price;
} elseif ($type == 'I') {
// per item
$shippingPrice = $request->getPackageQty() * $price - $this->getFreeBoxes() * $price;
} else {
$shippingPrice = false;
}
$shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice);
if ($shippingPrice !== false) {
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier('qquoteshiprate');
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod('qquoteshiprate');
if ($type == 'I') {
$method->setMethodTitle('Price per Item');
} else {
$method->setMethodTitle($this->getConfigData('name'));
}
if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
$shippingPrice = '0.00';
}
$method->setPrice($shippingPrice);
$method->setCost($shippingPrice);
$result->append($method);
}
return $result;
}
return false;
}
示例4: collectRates
/**
* Collect and get rates
*
* @param Mage_Shipping_Model_Rate_Request $request
* @return Mage_Shipping_Model_Rate_Result|bool|null
*/
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!$this->getConfigFlag('active')) {
return false;
}
$activeForCustomerGroup = Mage::helper('emjainteractive_shippingoption')->isShippingMethodAvailable();
if (!$activeForCustomerGroup) {
return false;
}
$freeBoxes = 0;
if ($request->getAllItems()) {
foreach ($request->getAllItems() as $item) {
if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
continue;
}
if ($item->getHasChildren() && $item->isShipSeparately()) {
foreach ($item->getChildren() as $child) {
if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
$freeBoxes += $item->getQty() * $child->getQty();
}
}
} elseif ($item->getFreeShipping()) {
$freeBoxes += $item->getQty();
}
}
}
$this->setFreeBoxes($freeBoxes);
$result = Mage::getModel('shipping/rate_result');
if ($this->getConfigData('type') == 'O') {
// per order
$shippingPrice = $this->getConfigData('price');
} elseif ($this->getConfigData('type') == 'I') {
// per item
$shippingPrice = $request->getPackageQty() * $this->getConfigData('price') - $this->getFreeBoxes() * $this->getConfigData('price');
} else {
$shippingPrice = false;
}
$shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice);
if ($shippingPrice !== false) {
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier('umosaco');
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod('umosaco');
$method->setMethodTitle($this->getConfigData('name'));
if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
$shippingPrice = '0.00';
}
$method->setPrice($shippingPrice);
$method->setCost($shippingPrice);
$result->append($method);
}
return $result;
}
示例5: collectRates
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!$this->getConfigFlag('active')) {
return false;
}
$freeBoxes = 0;
if ($request->getAllItems()) {
foreach ($request->getAllItems() as $item) {
if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
continue;
}
if ($item->getHasChildren() && $item->isShipSeparately()) {
foreach ($item->getChildren() as $child) {
if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
$freeBoxes += $item->getQty() * $child->getQty();
}
}
} elseif ($item->getFreeShipping()) {
$freeBoxes += $item->getQty();
}
}
}
$this->setFreeBoxes($freeBoxes);
$result = Mage::getModel('shipping/rate_result');
if ($this->getConfigData('type') == 'O') {
// per order
$shippingPrice = $this->getConfigData('price');
} elseif ($this->getConfigData('type') == 'I') {
// per item
$shippingPrice = $request->getPackageQty() * $this->getConfigData('price') - $this->getFreeBoxes() * $this->getConfigData('price');
} else {
$shippingPrice = false;
}
if (Mage_Shipping_Model_Carrier_Abstract::HANDLING_TYPE_PERCENT == $this->getConfigData('shipper_type')) {
$shippingPrice = $request->getData('base_subtotal_incl_tax') * $shippingPrice / 100;
}
$shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice);
if ($shippingPrice !== false) {
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier('flatrate');
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod('flatrate');
$method->setMethodTitle($this->getConfigData('name'));
if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
$shippingPrice = '0.00';
}
$method->setPrice($shippingPrice);
$method->setCost($shippingPrice);
$result->append($method);
}
return $result;
}
示例6: collectRates
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!Mage::getStoreConfig('carriers/' . $this->_code . '/active')) {
return false;
}
$destinationData = array('city' => ucwords(strtolower($request->getDestCity())), 'country_id' => $request->getDestCountryId(), 'postcode' => $request->getDestPostcode());
$quoteId = Mage::getSingleton('checkout/session')->getQuoteId();
$quote = Mage::getModel("sales/quote")->load($quoteId);
$result = Mage::getModel('aramexshipping/shipping')->getRatesAndPackages($quote, true, $destinationData);
$error = $result['error'];
$error_msg = isset($result['error_msg']) ? 'Aramex Error: ' . $result['error_msg'] : '';
$price = $result['price'];
$methodTitle = $request->getFreeShipping() ? Mage::helper('aramexshipping')->__('Free shipping applied') : '';
$handling = Mage::getStoreConfig('carriers/' . $this->_code . '/handling');
$result = Mage::getModel('shipping/rate_result');
if (!$error && $price > 0 || !$error && $request->getFreeShipping()) {
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier($this->_code);
$method->setMethod($this->_code);
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethodTitle($methodTitle);
$method->setPrice($price);
$method->setCost($price);
$result->append($method);
} else {
$error = Mage::getModel('shipping/rate_result_error');
$error->setCarrier($this->_code);
$error->setCarrierTitle($this->getConfigData('title'));
$error->setErrorMessage($error_msg ? $error_msg : $this->getConfigData('specificerrmsg'));
$result->append($error);
if ($error_msg) {
Mage::helper('aramexshipping')->log($error_msg, '', 'aramex_collect_rates');
Mage::helper('aramexshipping')->sendLogEmail(array('subject' => 'Collect Rates Error Log', 'content' => $error_msg));
}
}
return $result;
}
示例7: collectRates
/**
* Enter description here...
*
* @param Mage_Shipping_Model_Rate_Request $data
* @return Mage_Shipping_Model_Rate_Result
*/
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!$this->getConfigFlag('active')) {
return false;
}
$result = Mage::getModel('shipping/rate_result');
$packageValue = $request->getBaseCurrency()->convert($request->getPackageValue(), $request->getPackageCurrency());
$allow = $request->getFreeShipping() || $packageValue >= $this->getConfigData('cutoff_cost');
if ($allow) {
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier('freeshipping');
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod('freeshipping');
$method->setMethodTitle($this->getConfigData('name'));
$method->setPrice('0.00');
$method->setCost('0.00');
$result->append($method);
}
return $result;
}
示例8: collectRates
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!$this->getConfigFlag('active')) {
return false;
}
$freeBoxes = 0;
if ($request->getAllItems()) {
foreach ($request->getAllItems() as $item) {
if ($item->getFreeShipping() && !$item->getProduct()->isVirtual()) {
$freeBoxes += $item->getQty();
}
}
}
$this->setFreeBoxes($freeBoxes);
$result = Mage::getModel('shipping/rate_result');
if ($this->getConfigData('type') == 'O') {
// per order
$shippingPrice = $this->getConfigData('price');
} elseif ($this->getConfigData('type') == 'I') {
// per item
$shippingPrice = $request->getPackageQty() * $this->getConfigData('price') - $this->getFreeBoxes() * $this->getConfigData('price');
} else {
$shippingPrice = false;
}
$shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice);
if ($shippingPrice !== false) {
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier($this->_code);
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod($this->_code);
$method->setMethodTitle($this->getConfigData('name'));
if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
$shippingPrice = '0.00';
}
$method->setPrice($shippingPrice);
$method->setCost($shippingPrice);
$result->append($method);
}
return $result;
}
示例9: collectRates
/**
* Collect rates for this shipping method based on information in $request
*
* @param Mage_Shipping_Model_Rate_Request $data
* @return Mage_Shipping_Model_Rate_Result
*/
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
// skip if not enabled
if (!Mage::getStoreConfig('carriers/' . $this->_code . '/active')) {
return false;
}
$result = Mage::getModel('shipping/rate_result');
$packageValue = $request->getBaseCurrency()->convert($request->getPackageValue(), $request->getPackageCurrency());
$temp = array();
//get sheepla module config
$sConfig = Mage::getStoreConfig('sheepla');
//if user is using dynamic pricing
if ($sConfig['advanced']['use_dynamic_pricing']) {
//support admin and user checkout
if (Mage::getSingleton('admin/session')->isLoggedIn()) {
//admin
$quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
} else {
//user
$quote = Mage::getSingleton('checkout/session')->getQuote();
}
$items = $quote->getAllVisibleItems();
$address = $quote->getShippingAddress();
try {
$this->initSheeplaObjects();
$dpRates = $this->sp->getClient()->getDynamicPricing($address, $items);
$availableDynamicTemplateIds = array();
foreach ($dpRates as $rate) {
$availableDynamicTemplateIds[] = $rate['shipmentTemplateId'];
}
} catch (Exception $e) {
$dpRates = false;
Mage::Log('[Sheepla][' . date('Y-m-d H:i:s') . ']' . $e->getMessage());
}
} else {
$dpRates = false;
}
for ($i = 1; $i <= 10; $i++) {
if ($this->getMethodConfig('allowspecific', $i)) {
$availableCountries = explode(',', $this->getMethodConfig('specificcountry', $i));
if (!($availableCountries && in_array($request->getDestCountryId(), $availableCountries))) {
continue;
}
}
$shippingName = $this->getMethodConfig('name', $i);
$shippingPrice = $this->getMethodConfig('price', $i);
if (!empty($shippingName)) {
//if dynamic pricing enabled and method is not at dpRates table, skip this method
if (is_array($dpRates)) {
$shippingTemplateId = $this->getMethodConfig('template_id', $i);
if ($shippingTemplateId != '0' && !in_array($shippingTemplateId, $availableDynamicTemplateIds)) {
continue;
}
}
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier('sheepla');
$method->setMethod('method_' . $i);
$method->setMethodTitle($this->getMethodConfig('name', $i));
$method->setMethodDetails($this->getMethodConfig('desc', $i));
$method->setMethodDescription($this->getMethodConfig('desc', $i));
$method->setPrice(preg_replace('/,/', '.', $shippingPrice));
$method->setCost($this->getMethodConfig('cost', $i));
if (isset($sConfig['advanced']['custom_label']) && !empty($sConfig['advanced']['custom_label'])) {
$method->setCarrierTitle($sConfig['advanced']['custom_label']);
} else {
$method->setCarrierTitle(Mage::helper('sheepla/data')->__('Robust delivery by Sheepla!'));
}
//dynamic price calculate
if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
$method->setPrice('0.00');
} elseif (is_array($dpRates)) {
foreach ($sConfig as $k => $v) {
if ($method->getMethod() == $k) {
foreach ($dpRates as $rule) {
if ($rule['shipmentTemplateId'] == $v['template_id']) {
$method->setPrice($rule['price']);
}
}
}
}
}
$temp[$this->getMethodConfig('sort_order', $i)] = $method;
}
}
foreach ($temp as $m) {
$result->append($m);
}
return $result;
}
示例10: collectRates
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
try {
$process = array('result' => Mage::getModel('shipping/rate_result'), 'cart.items' => array(), 'products' => array(), 'data' => array('cart.price_excluding_tax' => $request->_data['package_value_with_discount'], 'cart.price_including_tax' => $request->_data['package_value_with_discount'], 'cart.weight' => $request->_data['package_weight'], 'cart.weight.unit' => null, 'cart.quantity' => $request->_data['package_qty'], 'cart.coupon' => Mage::getSingleton('checkout/cart')->getQuote()->getCouponCode(), 'shipto.country.code' => $request->_data['dest_country_id'], 'shipto.country.name' => null, 'shipto.region.code' => $request->_data['dest_region_code'], 'shipto.postal.code' => $request->_data['dest_postcode'], 'origin.country.code' => $request->_data['country_id'], 'origin.country.name' => null, 'origin.region.code' => $request->_data['region_id'], 'origin.postal.code' => $request->_data['postcode'], 'customer.group.id' => null, 'customer.group.code' => null, 'free_shipping' => $request->getFreeShipping(), 'store.id' => $request->_data['store_id'], 'store.code' => null, 'store.name' => null, 'store.address' => null, 'store.phone' => null, 'date.timestamp' => null, 'date.year' => null, 'date.month' => null, 'date.day' => null, 'date.hour' => null, 'date.minute' => null, 'date.second' => null), 'stop_to_first_match' => TRUE, 'config' => null);
// We don't need process certain products. If necessary, enable this block.
$items = $request->getAllItems();
for ($i = 0, $n = count($items); $i < $n; $i++) {
$item = $items[$i];
if ($item->getProduct() instanceof Mage_Catalog_Model_Product) {
$process['cart.items'][$item->getId()] = $item;
}
}
$this->_process($process);
return $process['result'];
} catch (Exception $e) {
Mage::logException($e);
}
}
示例11: _getFlatRate
/**
* @param Mage_Shipping_Model_Rate_Request $request
*
* @return Mage_Shipping_Model_Rate_Result
*/
protected function _getFlatRate(Mage_Shipping_Model_Rate_Request $request)
{
$freeBoxes = 0;
if ($request->getAllItems()) {
foreach ($request->getAllItems() as $item) {
if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
continue;
}
if ($item->getHasChildren() && $item->isShipSeparately()) {
foreach ($item->getChildren() as $child) {
if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
$freeBoxes += $item->getQty() * $child->getQty();
}
}
} elseif ($item->getFreeShipping()) {
$freeBoxes += $item->getQty();
}
}
}
$this->setFreeBoxes($freeBoxes);
$result = Mage::getModel('shipping/rate_result');
if ($this->getConfigData('type') == 'O') {
// per order
$shippingPrice = $this->getConfigData('type');
} elseif ($this->getConfigData('type') == 'I') {
// per item
$shippingPrice = $request->getPackageQty() * $this->getConfigData('price') - $this->getFreeBoxes() * $this->getConfigData('price');
} else {
$shippingPrice = 'O';
}
$shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice);
if ($shippingPrice !== false) {
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier($this->_code);
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod('flatrate');
$method->setMethodTitle($this->getConfigData('name'));
if (count($request->getAllItems()) > 0 && ($request->getFreeShipping() === true || $request->getPackageQty() !== null && $request->getPackageQty() == $this->getFreeBoxes())) {
$shippingPrice = '0.00';
}
$method->setPrice($shippingPrice);
$method->setCost($shippingPrice);
$result->append($method);
}
return $result;
}
示例12: collectRates
/**
* Enter description here...
*
* @param Mage_Shipping_Model_Rate_Request $data
* @return Mage_Shipping_Model_Rate_Result
*/
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!$this->getConfigFlag('active')) {
return false;
}
$freeBoxes = 0;
if ($request->getAllItems()) {
foreach ($request->getAllItems() as $item) {
if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
continue;
}
if ($item->getHasChildren() && $item->isShipSeparately()) {
foreach ($item->getChildren() as $child) {
if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
$freeBoxes += $item->getQty() * $child->getQty();
}
}
} elseif ($item->getFreeShipping()) {
$freeBoxes += $item->getQty();
}
}
}
$this->setFreeBoxes($freeBoxes);
$result = Mage::getModel('shipping/rate_result');
if ($this->getConfigData('type') == 'O') {
// per order
$shippingPrice = $this->getConfigData('price');
} elseif ($this->getConfigData('type') == 'I') {
// per item
$shippingPrice = $request->getPackageQty() * $this->getConfigData('price') - $this->getFreeBoxes() * $this->getConfigData('price');
} else {
$shippingPrice = false;
}
$voucher_code = Mage::getSingleton('core/session')->getData('voucher_code');
$voucher = $this->verify_voucher_code($voucher_code);
if ($voucher['order_type'] == '3MM') {
$shippingPrice = 18;
}
$shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice);
if ($shippingPrice !== false) {
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier('flatrate');
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod('flatrate');
$method->setMethodTitle($this->getConfigData('name'));
if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
$shippingPrice = '0.00';
}
$method->setPrice($shippingPrice);
$method->setCost($shippingPrice);
$result->append($method);
}
return $result;
}
示例13: collectRates
/**
* Enter description here...
*
* @param FCM_Shipping_Model_Rate_Request $data
* @return FCM_Shipping_Model_Rate_Result
*/
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
/* It will check whether Express shipping method is enable or not
if not it will return to calling function without executing further
*/
if (!$this->getConfigFlag('active')) {
return false;
}
$freeBoxes = 0;
if ($request->getAllItems()) {
foreach ($request->getAllItems() as $item) {
// Below line will check whether the product in question is virtual one or not
if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
continue;
}
// Below line will be executed whether item in cart are shipped seperatly or not
if ($item->getHasChildren() && $item->isShipSeparately()) {
foreach ($item->getChildren() as $child) {
if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
$freeBoxes += $item->getQty() * $child->getQty();
}
}
} elseif ($item->getFreeShipping()) {
$freeBoxes += $item->getQty();
}
}
}
$this->setFreeBoxes($freeBoxes);
$result = Mage::getModel('shipping/rate_result');
// this one check whether shipping will be calculated per order wise
if ($this->getConfigData('type') == 'O') {
$shippingPrice = $this->getConfigData('price');
} elseif ($this->getConfigData('type') == 'I') {
$shippingPrice = $request->getPackageQty() * $this->getConfigData('price') - $this->getFreeBoxes() * $this->getConfigData('price');
} else {
$shippingPrice = false;
}
$shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice);
if ($shippingPrice !== false) {
$method = Mage::getModel('shipping/rate_result_method');
//Set Shipping Carrier name as Express
$method->setCarrier('express');
//Fetch Express Shipping title which we have set from admin
$method->setCarrierTitle($this->getConfigData('title'));
//Set Shipping method name as express
$method->setMethod('express');
//Fetch Express Shipping name which we have set from admin
$method->setMethodTitle($this->getConfigData('name'));
/*
Check whether any free shipping promotion is being applied or not
if free shipping applied, below condition make the shipping price as 0
*/
if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
$shippingPrice = '0.00';
}
/*
set shipping Price and Cost as mention in admin configuration or Zero if any free shipping
promotion rule is applied
*/
$method->setPrice($shippingPrice);
$method->setCost($shippingPrice);
/* Append this shipping method with other shipping method which are in Enable state */
$result->append($method);
}
return $result;
}
示例14: collectRates
/**
* Enter description here...
*
* @param Mage_Shipping_Model_Rate_Request $data
* @return Mage_Shipping_Model_Rate_Result
*/
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!$this->getConfigFlag('active')) {
return false;
}
$freeBoxes = 0;
if ($request->getAllItems()) {
foreach ($request->getAllItems() as $item) {
if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
continue;
}
if ($item->getHasChildren() && $item->isShipSeparately()) {
foreach ($item->getChildren() as $child) {
if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
$freeBoxes += $item->getQty() * $child->getQty();
}
}
} elseif ($item->getFreeShipping()) {
$freeBoxes += $item->getQty();
}
}
}
$this->setFreeBoxes($freeBoxes);
$result = Mage::getModel('shipping/rate_result');
if ($this->getConfigData('type') == 'O') {
// per order
$shippingPrice = $this->getConfigData('price');
} elseif ($this->getConfigData('type') == 'I') {
// per item
$shippingPrice = $request->getPackageQty() * $this->getConfigData('price') - $this->getFreeBoxes() * $this->getConfigData('price');
} else {
$shippingPrice = false;
}
//$shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice);
$custom_ship = $this->get_pro_ship();
/*Mage::getSingleton('core/session', array('name'=>'frontend'));
$session = Mage::getSingleton('checkout/session');
$cart_items = $session->getQuote()->getAllItems();
$_helper = Mage::helper('catalog/output');
$product_shipping_price=0;
$flat_shipping_price = 0;
foreach( $cart_items as $items ){
$cur_fproduct = Mage::getModel('catalog/product')->load($items->getProduct_id());
$product_shipping_price = $_helper->productAttribute($cur_fproduct, $cur_fproduct->getShippingFlatratePerProduct(), 'shipping_flatrate_per_product');
if ($product_shipping_price == '') {
$flat_shipping_price += ($items) * ($this->getConfigData('price'));
}
}*/
//$shippingPrice = $custom_ship + $flat_shipping_price;
$shippingPrice = $custom_ship;
if ($shippingPrice !== false) {
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier('flatrate');
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod('flatrate');
$method->setMethodTitle($this->getConfigData('name'));
if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
$shippingPrice = '0.00';
}
$method->setPrice($shippingPrice);
$method->setCost($shippingPrice);
$result->append($method);
}
return $result;
}
示例15: collectRates
/**
* Collect rate to get shipping method
*
* @param Mage_Shipping_Model_Rate_Request $request
* @return Mage_Shipping_Model_Rate_Request $request
*/
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
$result = "";
$ship_price = 0;
if (!$this->getConfigFlag('active')) {
return false;
}
$website_id = (int) $request->getWebsiteId();
// Default condition Name: Weight vs. Destination
$weight = $request->getPackageWeight();
// Check Weight Limit
if ($this->getConfigFlag('active_weight_limit') && $weight >= $this->getConfigData('weight_limit')) {
return false;
}
// Condition Name: Price Vs. Destination
if ($this->getConfigData('condition_name') != $this->_default_condition_name) {
// The weight is now the price
$weight = Mage::helper('mmshippingplus')->getOrderAmount();
}
// Get country, region and postcode data
$country = Mage::helper('mmshippingplus')->getCustomerCountryCode();
$region = Mage::helper('mmshippingplus')->getCustomerRegionCode();
$postcode = Mage::helper('mmshippingplus')->getCustomerPostcode();
// Free shipping by qty
$freeQty = 0;
if ($request->getAllItems()) {
foreach ($request->getAllItems() as $item) {
if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
continue;
}
if ($item->getHasChildren() && $item->isShipSeparately()) {
foreach ($item->getChildren() as $child) {
if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
$freeQty += $item->getQty() * ($child->getQty() - (is_numeric($child->getFreeShipping()) ? $child->getFreeShipping() : 0));
}
}
} elseif ($item->getFreeShipping()) {
$freeQty += $item->getQty() - (is_numeric($item->getFreeShipping()) ? $item->getFreeShipping() : 0);
}
}
}
if (!$request->getConditionName()) {
$request->setConditionName($this->getConfigData('condition_name') ? $this->getConfigData('condition_name') : $this->_default_condition_name);
}
// Check tablerate with condition
$tablerate = Mage::getModel('mmshippingplus/shippingplus')->getCollection()->setOrder('weight', 'DESC')->addFieldToFilter('website_id', array('in' => $website_id))->addFieldToFilter('dest_country', array('in' => array('*', $country)))->addFieldToFilter('dest_zip', array('in' => array('*', $postcode)))->addFieldToFilter('dest_region', array('in' => array('*', $region)))->addFieldToFilter('weight', array('lteq' => $weight))->addFieldToFilter('type', array('eq' => $this->getConfigData('condition_name')));
// Tablerate price
$ship_price = $tablerate->getFirstItem()->getPrice();
// Price with shipping weight range
if ($this->getConfigFlag('active_ship_kg')) {
if ($this->getConfigData('ship_kg_country')) {
$kg_country = explode(',', $this->getConfigData('ship_kg_country'));
}
$country = Mage::helper('mmshippingplus')->getCustomerCountryCode(2);
if (in_array($country, $kg_country)) {
if ($weight >= $this->getConfigData('ship_from_kg') && $weight <= $this->getConfigData('ship_to_kg')) {
$ship_price = $this->getConfigData('ship_kg_price');
}
}
}
// Price with shipping price range
if ($this->getConfigFlag('active_ship_price')) {
if ($this->getConfigData('ship_price_country')) {
$price_country = explode(',', $this->getConfigData('ship_price_country'));
}
$country = Mage::helper('mmshippingplus')->getCustomerCountryCode(2);
if (in_array($country, $price_country)) {
$amount = Mage::helper('mmshippingplus')->getOrderAmount();
if ($amount >= $this->getConfigData('ship_from_price') && $amount <= $this->getConfigData('ship_to_price')) {
$ship_price = $this->getConfigData('ship_price_price');
}
}
}
if (!is_null($ship_price) && $ship_price != 0) {
// Free shipping by tablerate
$ship_price = $ship_price == $this->_free_ship_tablerate ? 0 : $ship_price;
// Check if price has charge
$charge = $tablerate->getFirstItem()->getCharge();
if ($charge > 0) {
$amount = Mage::helper('mmshippingplus')->getOrderAmount(MMind_Shippingplus_Model_Config_Source_Rangeprice::TYPE_SUBTOTAL);
// Charge type
if ($this->getConfigData('charge_type') == MMind_Shippingplus_Model_Config_Source_Charge::TYPE_CHARGE_FIX) {
// Fix price
$ship_price += $charge;
} else {
// Percentage price
$ship_price += $amount * $charge / 100;
}
}
// Package weight and qty free shipping
$oldWeight = $request->getPackageWeight();
$oldQty = $request->getPackageQty();
$request->setPackageWeight($request->getFreeMethodWeight());
$request->setPackageQty($oldQty - $freeQty);
//.........这里部分代码省略.........