Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Aquatuning Software Development - Bundle - Component
- *
- * @category Aquatuning
- * @package Shopware\Plugins\AtsdBundle
- * @copyright Copyright (c) 2013, Aquatuning GmbH
- */
- namespace Shopware\AtsdBundle\Bundle\StoreFrontBundle;
- /**
- * Aquatuning Software Development - Bundle - Component
- */
- class ListProductService implements \Shopware\Bundle\StoreFrontBundle\Service\ListProductServiceInterface
- {
- /**
- * The previously existing core service.
- *
- * @var \Shopware\Bundle\StoreFrontBundle\Service\ListProductServiceInterface
- */
- private $coreService;
- /**
- * The previously existing core service.
- *
- * @var \Shopware\AtsdBundle\Bundle\StoreFrontBundle\BundleService
- */
- private $bundleService;
- /**
- * The previously existing core service.
- *
- * @var \Shopware\AtsdBundle\Components\AtsdBundle
- */
- private $component;
- /**
- * DI container.
- *
- * @var \Shopware\Components\DependencyInjection\Container
- */
- protected $container;
- /**
- * Object constructor.
- *
- * @param \Shopware\Bundle\StoreFrontBundle\Service\ListProductServiceInterface $coreService
- * @param \Shopware\AtsdBundle\Bundle\StoreFrontBundle\BundleService $bundleService
- * @param \Shopware\AtsdBundle\Components\AtsdBundle $component
- * @param \Shopware\Components\DependencyInjection\Container $container
- *
- * @return \Shopware\AtsdBundle\Bundle\StoreFrontBundle\ListProductService
- */
- public function __construct(
- \Shopware\Bundle\StoreFrontBundle\Service\ListProductServiceInterface $coreService,
- \Shopware\AtsdBundle\Bundle\StoreFrontBundle\BundleService $bundleService,
- \Shopware\AtsdBundle\Components\AtsdBundle $component,
- \Shopware\Components\DependencyInjection\Container $container )
- {
- // set parameters
- $this->coreService = $coreService;
- $this->bundleService = $bundleService;
- $this->component = $component;
- $this->container = $container;
- }
- /**
- * ...
- *
- * @param array $numbers
- * @param \Shopware\Bundle\StoreFrontBundle\Struct\ProductContextInterface $context
- *
- * @return \Shopware\Bundle\StoreFrontBundle\Struct\ListProduct[]
- */
- public function getList( array $numbers, \Shopware\Bundle\StoreFrontBundle\Struct\ProductContextInterface $context )
- {
- // call core service
- $products = $this->coreService->getList( $numbers, $context );
- // get all bundles
- $bundles = $this->bundleService->getList( $products );
- // loop all products
- foreach ( $products as $product )
- {
- // we need an array to use ->get( "bundles" ) in the template
- $arr = ( isset( $bundles[$product->getId()] ) )
- ? $bundles[$product->getId()]
- : array();
- // add attribute
- $product->addAttribute(
- "atsd_bundle",
- new \Shopware\Bundle\StoreFrontBundle\Struct\Attribute( array( 'bundles' => $arr ) )
- );
- }
- // return the products
- return $products;
- }
- /**
- * ...
- *
- * @param string $number
- * @param \Shopware\Bundle\StoreFrontBundle\Struct\ProductContextInterface $context
- *
- * @return \Shopware\Bundle\StoreFrontBundle\Struct\ListProduct
- */
- public function get( $number, \Shopware\Bundle\StoreFrontBundle\Struct\ProductContextInterface $context )
- {
- // call our list
- $products = $this->getList( array( $number ), $context );
- // return first product
- return array_shift( $products );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment