예제 #1
0
 /**
  * Copys all data from a given service item.
  *
  * @param \Aimeos\MShop\Service\Item\Iface $service New service item
  */
 public function copyFrom(\Aimeos\MShop\Service\Item\Iface $service)
 {
     $this->setCode($service->getCode());
     $this->setName($service->getName());
     $this->setType($service->getType());
     $this->setServiceId($service->getId());
     $items = $service->getRefItems('media', 'default', 'default');
     if (($item = reset($items)) !== false) {
         $this->setMediaUrl($item->getUrl());
     }
     $this->setModified();
 }
예제 #2
0
 /**
  * Returns the service provider which is responsible for the service item.
  *
  * @param \Aimeos\MShop\Service\Item\Iface $item Delivery or payment service item object
  * @return \Aimeos\MShop\Service\Provider\Iface Returns a service provider implementing \Aimeos\MShop\Service\Provider\Iface
  * @throws \Aimeos\MShop\Service\Exception If provider couldn't be found
  */
 public function getProvider(\Aimeos\MShop\Service\Item\Iface $item)
 {
     $type = ucwords($item->getType());
     $names = explode(',', $item->getProvider());
     if (ctype_alnum($type) === false) {
         throw new \Aimeos\MShop\Service\Exception(sprintf('Invalid characters in type name "%1$s"', $type));
     }
     if (($provider = array_shift($names)) === null) {
         throw new \Aimeos\MShop\Service\Exception(sprintf('Provider in "%1$s" not available', $item->getProvider()));
     }
     if (ctype_alnum($provider) === false) {
         throw new \Aimeos\MShop\Service\Exception(sprintf('Invalid characters in provider name "%1$s"', $provider));
     }
     $interface = '\\Aimeos\\MShop\\Service\\Provider\\Factory\\Iface';
     $classname = '\\Aimeos\\MShop\\Service\\Provider\\' . $type . '\\' . $provider;
     if (class_exists($classname) === false) {
         throw new \Aimeos\MShop\Service\Exception(sprintf('Class "%1$s" not available', $classname));
     }
     $context = $this->getContext();
     $config = $context->getConfig();
     $provider = new $classname($context, $item);
     if ($provider instanceof $interface === false) {
         $msg = sprintf('Class "%1$s" does not implement interface "%2$s"', $classname, $interface);
         throw new \Aimeos\MShop\Service\Exception($msg);
     }
     /** mshop/service/provider/delivery/decorators
      * Adds a list of decorators to all delivery provider objects automatcally
      *
      * Decorators extend the functionality of a class by adding new aspects
      * (e.g. log what is currently done), executing the methods of the underlying
      * class only in certain conditions (e.g. only for logged in users) or
      * modify what is returned to the caller.
      *
      * This option allows you to wrap decorators
      * ("\Aimeos\MShop\Service\Provider\Decorator\*") around the delivery provider.
      *
      *  mshop/service/provider/delivery/decorators = array( 'decorator1' )
      *
      * This would add the decorator named "decorator1" defined by
      * "\Aimeos\MShop\Service\Provider\Decorator\Decorator1" to all delivery provider
      * objects.
      *
      * @param array List of decorator names
      * @since 2014.03
      * @category Developer
      * @see mshop/service/provider/payment/decorators
      */
     /** mshop/service/provider/payment/decorators
      * Adds a list of decorators to all payment provider objects automatcally
      *
      * Decorators extend the functionality of a class by adding new aspects
      * (e.g. log what is currently done), executing the methods of the underlying
      * class only in certain conditions (e.g. only for logged in users) or
      * modify what is returned to the caller.
      *
      * This option allows you to wrap decorators
      * ("\Aimeos\MShop\Service\Provider\Decorator\*") around the payment provider.
      *
      *  mshop/service/provider/payment/decorators = array( 'decorator1' )
      *
      * This would add the decorator named "decorator1" defined by
      * "\Aimeos\MShop\Service\Provider\Decorator\Decorator1" to all payment provider
      * objects.
      *
      * @param array List of decorator names
      * @since 2014.03
      * @category Developer
      * @see mshop/service/provider/delivery/decorators
      */
     $decorators = $config->get('mshop/service/provider/' . $item->getType() . '/decorators', array());
     $provider = $this->addServiceDecorators($item, $provider, $names);
     return $this->addServiceDecorators($item, $provider, $decorators);
 }