/**
  * @param RateRequest $request
  * @return \Magento\Shipping\Model\Rate\Result
  */
 public function collectRates(RateRequest $request)
 {
     if (!$this->getConfigFlag('active')) {
         return false;
     }
     /** @var Result $result */
     $result = $this->_rateResultFactory->create();
     $packageValue = $request->getBaseCurrency()->convert($request->getPackageValue(), $request->getPackageCurrency());
     for ($i = 0; $i <= 5; $i++) {
         if ($this->getConfigData('type' . $i) == 'O') {
             // per order
             $shippingPrice = $this->getConfigData('price' . $i);
         } elseif ($this->getConfigData('type' . $i) == 'I') {
             // per item
             $shippingPrice = $request->getPackageQty() * $this->getConfigData('price' . $i) - $this->getFreeBoxes() * $this->getConfigData('price' . $i);
         } else {
             $shippingPrice = $this->getConfigData('price' . $i);
         }
         $shippingName = $this->getConfigData('name' . $i);
         if ($shippingName != "" && ($packageValue >= $this->getConfigData('min_shipping' . $i) && $packageValue <= $this->getConfigData('max_shipping' . $i)) or $shippingName != "" && $this->getConfigData('max_shipping' . $i) == "") {
             /** @var \Magento\Quote\Model\Quote\Address\RateResult\Method $method */
             $method = $this->_rateMethodFactory->create();
             $method->setCarrier('msmultiflat');
             $method->setCarrierTitle($this->getConfigData('title'));
             $method->setMethod($this->getConfigData('name' . $i));
             $method->setMethodTitle($this->getConfigData('name' . $i));
             $method->setMethodDetails($this->getConfigData('details' . $i));
             $method->setMethodDescription($this->getConfigData('details' . $i));
             $method->setPrice($shippingPrice);
             $method->setCost($shippingPrice);
             $result->append($method);
         }
     }
     return $result;
 }
 /**
  *
  * @param RateRequest $request
  * @return boolean
  */
 public function collectRates(RateRequest $request)
 {
     if (!$this->isActive()) {
         return false;
     }
     $config = $this->getConfig($request);
     // $stopToFirstMatch = (boolean)$this->getConfigData('stop_to_first_match');
     /** @var \Magento\Shipping\Model\Rate\Result $result */
     $result = $this->rateFactory->create();
     if (!isset($config) || !is_array($config)) {
         $this->_logger->debug("Owebia_AdvancedShippingSetting : Invalid config");
         return false;
     }
     foreach ($config as $methodId => $method) {
         if (isset($method->error)) {
             $this->appendError($result, $methodId, $method, $method->error);
         } elseif (!isset($method->price)) {
             $this->appendError($result, $methodId, $method, "Invalid price: null");
         } elseif ($method->price === false) {
             $this->appendError($result, $methodId, $method, "Invalid price: false");
         } elseif (isset($method->enabled) && !$method->enabled) {
             // $this->appendError($result, $methodId, $method, "Method disabled");
         } elseif (isset($method->debug)) {
             $this->appendError($result, $methodId, $method, $method->debug);
         } else {
             $rate = $this->createMethod($methodId, $method);
             $result->append($rate);
             // if ($stopToFirstMatch) break;
         }
     }
     return $result;
 }
Example #3
0
 /**
  * @param RateRequest $request
  * @return bool|Result|null
  */
 public function collectRates(RateRequest $request)
 {
     if (!$this->getConfigFlag('active')) {
         return false;
     }
     $expressAvailable = true;
     $expressMaxWeight = $this->getConfigData('express_max_weight');
     $shippingTotalWeight = 0;
     $this->_result = $this->_rateResultFactory->create();
     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()) {
                         $shippingTotalWeight += $child->getWeight();
                     }
                 }
             } elseif ($item->getFreeShipping()) {
                 $shippingTotalWeight += $item->getWeight();
             }
         }
     }
     if ($shippingTotalWeight > $expressMaxWeight) {
         $expressAvailable = false;
     }
     if ($expressAvailable) {
         $this->_getExpressRate();
     }
     $this->_getStandardRate();
     return $this->getResult();
 }
Example #4
0
 /**
  * @param \Magento\Framework\Object $request
  * @return Result|bool
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function collectRates(\Magento\Framework\Object $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\Quote\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;
 }
 /**
  * Collect and get rates for storefront
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  * @param RateRequest $request
  * @return DataObject|bool|null
  * @api
  */
 public function collectRates(RateRequest $request)
 {
     /**
      * Make sure that Shipping method is enabled
      */
     if (!$this->isActive()) {
         return false;
     }
     /** @var \Magento\Shipping\Model\Rate\Result $result */
     $result = $this->_rateResultFactory->create();
     $shippingPrice = $this->getConfigData('price');
     $method = $this->_rateMethodFactory->create();
     /**
      * Set carrier's method data
      */
     $method->setCarrier($this->getCarrierCode());
     $method->setCarrierTitle($this->getConfigData('title'));
     /**
      * Displayed as shipping method under Carrier
      */
     $method->setMethod($this->getCarrierCode());
     $method->setMethodTitle($this->getConfigData('name'));
     $method->setPrice($shippingPrice);
     $method->setCost($shippingPrice);
     $result->append($method);
     return $result;
 }
 /**
  * @param RateRequest $request
  * @return Result|bool
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function collectRates(RateRequest $request)
 {
     if (!$this->getConfigFlag('active')) {
         return false;
     }
     $freeBoxes = $this->getFreeBoxesCount($request);
     $this->setFreeBoxes($freeBoxes);
     /** @var Result $result */
     $result = $this->_rateResultFactory->create();
     $shippingPrice = $this->getShippingPrice($request, $freeBoxes);
     if ($shippingPrice !== false) {
         $method = $this->createResultMethod($shippingPrice);
         $result->append($method);
     }
     return $result;
 }
Example #7
0
 /**
  * Get shipping rate result model
  *
  * @return \Magento\Shipping\Model\Rate\Result
  */
 public function getResult()
 {
     if (empty($this->_result)) {
         $this->_result = $this->_rateResultFactory->create();
     }
     return $this->_result;
 }
Example #8
0
 /**
  * @param RateRequest $request
  * @return \Magento\Shipping\Model\Rate\Result
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 public function collectRates(RateRequest $request)
 {
     if (!$this->getConfigFlag('active')) {
         return false;
     }
     /** @var \Magento\Shipping\Model\Rate\Result $result */
     $result = $this->_rateResultFactory->create();
     $shippingPrice = $this->getConfigData('price');
     $method = $this->_rateMethodFactory->create();
     $method->setCarrier($this->_code);
     $method->setCarrierTitle($this->getConfigData('title'));
     $method->setMethod($this->_code);
     $method->setMethodTitle($this->getConfigData('name'));
     $method->setPrice($shippingPrice);
     $method->setCost($shippingPrice);
     $result->append($method);
     return $result;
 }
Example #9
0
 /**
  *
  * @param RateRequest $request
  * @return boolean
  */
 public function collectRates(RateRequest $request)
 {
     if (!$this->isActive()) {
         return false;
     }
     $config = $this->getConfig($request);
     // $stopToFirstMatch = (boolean)$this->getConfigData('stop_to_first_match');
     /** @var \Magento\Shipping\Model\Rate\Result $result */
     $result = $this->rateFactory->create();
     if (!isset($config) || !is_array($config)) {
         $this->_logger->debug("OWEBIA SHIPPING : Invalid config");
         return false;
     }
     foreach ($config as $methodId => $method) {
         if (isset($method->error)) {
             $this->appendError($result, $methodId, $method, $method->error);
         } elseif (!isset($method->price)) {
             $this->appendError($result, $methodId, $method, "Invalid price: null");
         } elseif ($method->price === false) {
             $this->appendError($result, $methodId, $method, "Invalid price: false");
         } elseif (isset($method->enabled) && !$method->enabled) {
             // $this->appendError($result, $methodId, $method, "Method disabled");
         } elseif (isset($method->debug)) {
             $this->appendError($result, $methodId, $method, $method->debug);
         } else {
             /** @var \Magento\Quote\Model\Quote\Address\RateResult\Method $rate */
             $rate = $this->rateMethodFactory->create();
             $rate->setCarrier($this->_code);
             $rate->setCarrierTitle($this->getConfigData('title'));
             $rate->setMethod($methodId);
             $title = isset($method->title) ? $method->title : 'N/A';
             $rate->setMethodTitle($title);
             $description = isset($method->description) ? $method->description : null;
             $rate->setMethodDescription($description);
             $rate->setCost($method->price);
             $rate->setPrice($method->price);
             $result->append($rate);
             // if ($stopToFirstMatch) break;
         }
     }
     return $result;
 }
Example #10
0
 /**
  * @param \Magento\Framework\Object $request
  * @return \Magento\Shipping\Model\Rate\Result
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 public function collectRates(\Magento\Framework\Object $request)
 {
     if (!$this->getConfigFlag('active')) {
         return false;
     }
     /** @var \Magento\Shipping\Model\Rate\Result $result */
     $result = $this->_rateResultFactory->create();
     if (!empty($rate)) {
         /** @var \Magento\Quote\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;
 }
Example #11
0
 /**
  * Collect and get rates
  *
  * @param \Magento\Framework\Object $request
  * @return \Magento\Shipping\Model\Rate\Result|bool
  */
 public function collectRates(\Magento\Framework\Object $request)
 {
     /**
      * Make sure that Shipping method is enabled
      */
     if (!$this->isActive()) {
         return false;
     }
     /**
      * Build Rate for each location
      * Each Rate displayed as shipping method under Carrier(In-Store Pickup) on frontend
      */
     /** @var \Magento\Shipping\Model\Rate\Result $result */
     $result = $this->rateResultFactory->create();
     foreach ($this->getLocations() as $locationId => $location) {
         $method = $this->buildRateForLocation($locationId, $location);
         $result->append($method);
     }
     return $result;
 }
 /**
  * @param RateRequest $request
  * @return \Magento\Shipping\Model\Rate\Result|bool
  */
 public function collectRates(RateRequest $request)
 {
     if (!$this->getConfigFlag('active')) {
         return false;
     }
     #print_r(get_class_methods($request));
     $info = array('city' => $request->getDestCity(), 'company' => $request->getDestCompany(), 'country_id' => $request->getDestCountryId(), 'firstname' => $request->getDestFirstname(), 'lastname' => $request->getDestLastname(), 'postcode' => $request->getDestPostcode(), 'region' => $request->getDestRegion(), 'region_code' => $request->getDestRegionCode(), 'region_id' => $request->getDestRegionId(), 'street' => $request->getDestStreet(), 'telphone' => $request->getDestTelphone());
     #$this->_logger->addDebug('$info');
     $this->_logger->log(100, print_r($info, true));
     $quoteArr = null;
     foreach ($request->getAllItems() as $item) {
         $quoteArr['item_id'] = $item->getitem_id();
         $quoteArr['quote_id'] = $item->getquote_id();
         $quoteArr['product_id'] = $item->getproduct_id();
         $quoteArr['parent_item_id'] = $item->getparent_item_id();
         $quoteArr['is_virtual'] = $item->getis_virtual();
         $quoteArr['sku'] = $item->getsku();
         $quoteArr['name'] = $item->getname();
         $quoteArr['qty'] = $item->getqty();
         $quoteArr['weight'] = $item->getweight();
         $quoteArr['price'] = $item->getprice();
         $quoteArr['base_price'] = $item->getbase_price();
         $quoteArr['custom_price'] = $item->getcustom_price();
         $quoteArr['discount_percent'] = $item->getdiscount_percent();
         $quoteArr['discount_amount'] = $item->getdiscount_amount();
     }
     #$this->_logger->addDebug('测试');
     $this->_logger->log(100, print_r($quoteArr, true));
     /** @var \Magento\Shipping\Model\Rate\Result $result */
     $result = $this->_rateResultFactory->create();
     $shippingPrice = $this->getConfigData('price');
     $method = $this->_rateMethodFactory->create();
     $method->setCarrier($this->_code);
     $method->setCarrierTitle($this->getConfigData('title'));
     $method->setMethod($this->_code);
     $method->setMethodTitle($this->getConfigData('name'));
     $method->setPrice($shippingPrice);
     $method->setCost($shippingPrice);
     $result->append($method);
     return $result;
 }
 /**
  * FreeShipping Rates Collector
  *
  * @param RateRequest $request
  * @return \Magento\Shipping\Model\Rate\Result|bool
  */
 public function collectRates(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\Quote\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;
 }
 /**
  * @param RateRequest $request
  *
  * @return bool|Result
  */
 public function collectRates(RateRequest $request)
 {
     if (!$this->isActive()) {
         return false;
     }
     $this->_request = $request;
     /** @var \Magento\Shipping\Model\Rate\Result $result */
     $result = $this->_rateResultFactory->create();
     foreach (array_keys($this->getAllowedMethods()) as $methodId) {
         $rate = $this->_getRate($methodId);
         $result->append($rate);
     }
     return $result;
 }
Example #15
0
 /**
  * @param RateRequest $request
  * @return bool|Result|null
  */
 public function collectRates(RateRequest $request)
 {
     if (!$this->getConfigFlag('active')) {
         return false;
     }
     $expressAvailable = true;
     //        $expressMaxWeight = $this->getConfigData('express_max_weight');
     $shippingTotalWeight = 0;
     $this->_result = $this->_rateResultFactory->create();
     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()) {
                         $shippingTotalWeight += $child->getWeight();
                     }
                 }
             } elseif ($item->getFreeShipping()) {
                 $shippingTotalWeight += $item->getWeight();
             }
         }
     }
     //        if ($shippingTotalWeight > $expressMaxWeight) {
     //            $expressAvailable = false;
     //        }
     //        if ($expressAvailable) {
     //            $this->_getExpressRate();
     //        }
     $this->soap_init();
     $rates = $this->get_services();
     print_r($rates);
     die;
     //        $rates = $this->getAllowedMethods();
     foreach ($rates as $key => $rated) {
         $rate = $this->_rateMethodFactory->create();
         $rate->setCarrier($this->_code);
         $rate->setCarrierTitle($this->getConfigData('title'));
         $rate->setMethodTitle($rated);
         $rate->setPrice(1.23);
         $rate->setCost(0);
         $this->_result->append($rate);
         //            return $this;
     }
     return $this->getResult();
 }
Example #16
0
 /**
  * @param RateRequest $request
  * @return \Magento\Shipping\Model\Rate\Result
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function collectRates(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\Quote\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\Quote\Model\Quote\Address\RateResult\Error $error */
         $error = $this->_rateErrorFactory->create(['data' => ['carrier' => $this->_code, 'carrier_title' => $this->getConfigData('title'), 'error_message' => $this->getConfigData('specificerrmsg')]]);
         $result->append($error);
     }
     return $result;
 }
Example #17
0
 /**
  * @param $ratesToAdd
  * @return \Magento\Shipping\Model\Rate\Result
  */
 public function createMergedRate($ratesToAdd)
 {
     $result = $this->rateFactory->create();
     foreach ($ratesToAdd as $rateToAdd) {
         $method = $this->rateMethodFactory->create();
         $method->setPrice((double) $rateToAdd['price']);
         $method->setCost((double) $rateToAdd['price']);
         $method->setCarrier($this->_code);
         $method->setCarrierTitle($rateToAdd['mergedTitle']);
         $method->setMethod($rateToAdd['title']);
         $method->setMethodTitle($rateToAdd['title']);
         $method->setMethodDescription($rateToAdd['mergedDescription']);
         $method->setCarrierType(__('multiple_shipments'));
         $result->append($method);
     }
     return $result;
 }