コード例 #1
0
 /**
  * Given a Cart, return a set of Valid ShippingRanges satisfied.
  *
  * @param ShippingCollectionEvent $event Event
  *
  * @return $this Self object
  */
 public function addCustomShippingMethods(ShippingCollectionEvent $event)
 {
     if (!$this->plugin->isEnabled()) {
         return $this;
     }
     $cart = $event->getCart();
     $carrierRanges = $this->shippingRangesProvider->getAllShippingRangesSatisfiedWithCart($cart);
     foreach ($carrierRanges as $carrierRange) {
         $event->addShippingMethod(new ShippingMethod('custom-shipping-method-' . $carrierRange->getId(), $carrierRange->getCarrier()->getName(), $carrierRange->getName(), '', $carrierRange->getPrice()));
     }
 }
コード例 #2
0
 /**
  * Test getAllShippingRangesSatisfiedWithCart method
  *
  * @dataProvider dataGetAllShippingRangesSatisfiedWithCart
  */
 public function testGetAllShippingRangesSatisfiedWithCart($withCarrier, $priceFrom, $priceTo, $priceRangePrice, $weightFrom, $weightTo, $weightRangePrice, $currencyConverterMultiplier, $hasResult)
 {
     $shippingCollectEventListener = new ShippingRangesProvider($this->getBuiltCarrierRepository($withCarrier, $priceFrom, $priceTo, $priceRangePrice, $weightFrom, $weightTo, $weightRangePrice)->reveal(), $this->getCurrencyConverter($currencyConverterMultiplier)->reveal(), $this->getZoneMatcher()->reveal());
     $shippingRanges = $shippingCollectEventListener->getAllShippingRangesSatisfiedWithCart($this->getRevealedCart());
     $this->assertCount($hasResult, $shippingRanges);
 }