示例#1
0
 /**
  * @param string $name
  * @param string|null $code
  * @param int|null $position
  * @param ZoneInterface|null $zone
  * @param string $locale
  * @param array $configuration
  * @param string $calculator
  * @param bool $enabled
  * @param bool $addForCurrentChannel
  * @param array $channels
  *
  * @return ShippingMethodInterface
  */
 private function createShippingMethod($name, $code = null, $position = null, ZoneInterface $zone = null, $locale = 'en', array $configuration = [], $calculator = DefaultCalculators::FLAT_RATE, $enabled = true, $addForCurrentChannel = true, array $channels = [])
 {
     $channel = $this->sharedStorage->get('channel');
     if (null === $zone) {
         $zone = $this->sharedStorage->get('zone');
     }
     if (null === $code) {
         $code = $this->generateCodeFromNameAndZone($name, $zone->getCode());
     }
     if (empty($configuration)) {
         $configuration = $this->getConfigurationByChannels([$channel]);
     }
     /** @var ShippingMethodInterface $shippingMethod */
     $shippingMethod = $this->shippingMethodFactory->createNew();
     $shippingMethod->setCode($code);
     $shippingMethod->setName($name);
     $shippingMethod->setPosition($position);
     $shippingMethod->setCurrentLocale($locale);
     $shippingMethod->setConfiguration($configuration);
     $shippingMethod->setCalculator($calculator);
     $shippingMethod->setZone($zone);
     $shippingMethod->setEnabled($enabled);
     if ($addForCurrentChannel && $channel) {
         $shippingMethod->addChannel($channel);
     }
     if (!$addForCurrentChannel) {
         foreach ($channels as $channel) {
             $shippingMethod->addChannel($channel);
         }
     }
     $this->shippingMethodRepository->add($shippingMethod);
     $this->sharedStorage->set('shipping_method', $shippingMethod);
     return $shippingMethod;
 }
示例#2
0
 /**
  * @param string $name
  * @param string|null $code
  * @param int|null $position
  * @param ZoneInterface|null $zone
  * @param string $locale
  * @param array $configuration
  * @param string $calculator
  * @param bool $enabled
  * @param bool $addForCurrentChannel
  */
 private function createShippingMethod($name, $code = null, $position = null, ZoneInterface $zone = null, $locale = 'en', $configuration = ['amount' => 0], $calculator = DefaultCalculators::FLAT_RATE, $enabled = true, $addForCurrentChannel = true)
 {
     if (null === $zone) {
         $zone = $this->sharedStorage->get('zone');
     }
     if (null === $code) {
         $code = $this->generateCodeFromNameAndZone($name, $zone->getCode());
     }
     /** @var ShippingMethodInterface $shippingMethod */
     $shippingMethod = $this->shippingMethodFactory->createNew();
     $shippingMethod->setCode($code);
     $shippingMethod->setName($name);
     $shippingMethod->setPosition($position);
     $shippingMethod->setCurrentLocale($locale);
     $shippingMethod->setConfiguration($configuration);
     $shippingMethod->setCalculator($calculator);
     $shippingMethod->setZone($zone);
     $shippingMethod->setEnabled($enabled);
     if ($addForCurrentChannel && $this->sharedStorage->has('channel')) {
         $channel = $this->sharedStorage->get('channel');
         $channel->addShippingMethod($shippingMethod);
     }
     $this->shippingMethodRepository->add($shippingMethod);
     $this->sharedStorage->set('shipping_method', $shippingMethod);
 }
示例#3
0
 /**
  * @param string $name
  * @param ZoneInterface|null $zone
  * @param string $locale
  * @param array $configuration
  * @param string $calculator
  */
 private function createShippingMethod($name, ZoneInterface $zone = null, $locale = 'en', $configuration = ['amount' => 0], $calculator = DefaultCalculators::FLAT_RATE)
 {
     if (null === $zone) {
         $zone = $this->sharedStorage->get('zone');
     }
     /** @var ShippingMethodInterface $shippingMethod */
     $shippingMethod = $this->shippingMethodFactory->createNew();
     $shippingMethod->setCode($this->generateCodeFromNameAndZone($name, $zone->getCode()));
     $shippingMethod->setName($name);
     $shippingMethod->setCurrentLocale($locale);
     $shippingMethod->setConfiguration($configuration);
     $shippingMethod->setCalculator($calculator);
     $shippingMethod->setZone($zone);
     $this->shippingMethodRepository->add($shippingMethod);
 }