Esempio n. 1
0
 /**
  * @return $this
  */
 protected function _getExpressRate()
 {
     $rate = $this->_rateMethodFactory->create();
     $rate->setCarrier($this->_code);
     $rate->setCarrierTitle($this->getConfigData('title'));
     $rate->setMethodTitle('Express delivery');
     $rate->setPrice(2.5);
     $rate->setCost(0);
     $this->_result->append($rate);
     return $this;
 }
Esempio n. 2
0
 /**
  * @param \Magento\Sales\Model\Quote\Address\RateRequest $request
  * @return \Magento\Shipping\Model\Rate\Result
  */
 public function collectRates(\Magento\Sales\Model\Quote\Address\RateRequest $request)
 {
     if (!$this->getConfigFlag('active')) {
         return false;
     }
     /** @var \Magento\Shipping\Model\Rate\Result $result */
     $result = $this->_rateResultFactory->create();
     if (!empty($rate)) {
         /** @var \Magento\Sales\Model\Quote\Address\RateResult\Method $method */
         $method = $this->_rateMethodFactory->create();
         $method->setCarrier('pickup');
         $method->setCarrierTitle($this->getConfigData('title'));
         $method->setMethod('store');
         $method->setMethodTitle(__('Store Pickup'));
         $method->setPrice(0);
         $method->setCost(0);
         $result->append($method);
     }
     return $result;
 }
Esempio n. 3
0
 /**
  * FreeShipping Rates Collector
  *
  * @param \Magento\Sales\Model\Quote\Address\RateRequest $request
  * @return \Magento\Shipping\Model\Rate\Result|bool
  */
 public function collectRates(\Magento\Sales\Model\Quote\Address\RateRequest $request)
 {
     if (!$this->getConfigFlag('active')) {
         return false;
     }
     /** @var \Magento\Shipping\Model\Rate\Result $result */
     $result = $this->_rateResultFactory->create();
     $this->_updateFreeMethodQuote($request);
     if ($request->getFreeShipping() || $request->getBaseSubtotalInclTax() >= $this->getConfigData('free_shipping_subtotal')) {
         /** @var \Magento\Sales\Model\Quote\Address\RateResult\Method $method */
         $method = $this->_rateMethodFactory->create();
         $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;
 }
Esempio n. 4
0
 /**
  * @param \Magento\Sales\Model\Quote\Address\RateRequest $request
  * @return Result|bool
  */
 public function collectRates(\Magento\Sales\Model\Quote\Address\RateRequest $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);
     /** @var Result $result */
     $result = $this->_rateResultFactory->create();
     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) {
         /** @var \Magento\Sales\Model\Quote\Address\RateResult\Method $method */
         $method = $this->_rateMethodFactory->create();
         $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;
 }
Esempio n. 5
0
 /**
  * @param \Magento\Sales\Model\Quote\Address\RateRequest $request
  * @return \Magento\Shipping\Model\Rate\Result
  */
 public function collectRates(\Magento\Sales\Model\Quote\Address\RateRequest $request)
 {
     if (!$this->getConfigFlag('active')) {
         return false;
     }
     // exclude Virtual products price from Package value if pre-configured
     if (!$this->getConfigFlag('include_virtual_price') && $request->getAllItems()) {
         foreach ($request->getAllItems() as $item) {
             if ($item->getParentItem()) {
                 continue;
             }
             if ($item->getHasChildren() && $item->isShipSeparately()) {
                 foreach ($item->getChildren() as $child) {
                     if ($child->getProduct()->isVirtual()) {
                         $request->setPackageValue($request->getPackageValue() - $child->getBaseRowTotal());
                     }
                 }
             } elseif ($item->getProduct()->isVirtual()) {
                 $request->setPackageValue($request->getPackageValue() - $item->getBaseRowTotal());
             }
         }
     }
     // Free shipping by qty
     $freeQty = 0;
     if ($request->getAllItems()) {
         $freePackageValue = 0;
         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()) {
                         $freeShipping = is_numeric($child->getFreeShipping()) ? $child->getFreeShipping() : 0;
                         $freeQty += $item->getQty() * ($child->getQty() - $freeShipping);
                     }
                 }
             } elseif ($item->getFreeShipping()) {
                 $freeShipping = is_numeric($item->getFreeShipping()) ? $item->getFreeShipping() : 0;
                 $freeQty += $item->getQty() - $freeShipping;
                 $freePackageValue += $item->getBaseRowTotal();
             }
         }
         $oldValue = $request->getPackageValue();
         $request->setPackageValue($oldValue - $freePackageValue);
     }
     if (!$request->getConditionName()) {
         $conditionName = $this->getConfigData('condition_name');
         $request->setConditionName($conditionName ? $conditionName : $this->_defaultConditionName);
     }
     // Package weight and qty free shipping
     $oldWeight = $request->getPackageWeight();
     $oldQty = $request->getPackageQty();
     $request->setPackageWeight($request->getFreeMethodWeight());
     $request->setPackageQty($oldQty - $freeQty);
     /** @var \Magento\Shipping\Model\Rate\Result $result */
     $result = $this->_rateResultFactory->create();
     $rate = $this->getRate($request);
     $request->setPackageWeight($oldWeight);
     $request->setPackageQty($oldQty);
     if (!empty($rate) && $rate['price'] >= 0) {
         /** @var \Magento\Sales\Model\Quote\Address\RateResult\Method $method */
         $method = $this->_resultMethodFactory->create();
         $method->setCarrier('tablerate');
         $method->setCarrierTitle($this->getConfigData('title'));
         $method->setMethod('bestway');
         $method->setMethodTitle($this->getConfigData('name'));
         if ($request->getFreeShipping() === true || $request->getPackageQty() == $freeQty) {
             $shippingPrice = 0;
         } else {
             $shippingPrice = $this->getFinalPriceWithHandlingFee($rate['price']);
         }
         $method->setPrice($shippingPrice);
         $method->setCost($rate['cost']);
         $result->append($method);
     } else {
         /** @var \Magento\Sales\Model\Quote\Address\RateResult\Error $error */
         $error = $this->_rateErrorFactory->create(array('data' => array('carrier' => $this->_code, 'carrier_title' => $this->getConfigData('title'), 'error_message' => $this->getConfigData('specificerrmsg'))));
         $result->append($error);
     }
     return $result;
 }