Guest User

Untitled

a guest
Aug 12th, 2015
738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Aquatuning Software Development - Bundle - Component
  5. *
  6. * @category Aquatuning
  7. * @package Shopware\Plugins\AtsdBundle
  8. * @copyright Copyright (c) 2013, Aquatuning GmbH
  9. */
  10.  
  11. namespace Shopware\AtsdBundle\Bundle\StoreFrontBundle;
  12.  
  13.  
  14.  
  15. /**
  16. * Aquatuning Software Development - Bundle - Component
  17. */
  18.  
  19. class ListProductService implements \Shopware\Bundle\StoreFrontBundle\Service\ListProductServiceInterface
  20. {
  21.  
  22. /**
  23. * The previously existing core service.
  24. *
  25. * @var \Shopware\Bundle\StoreFrontBundle\Service\ListProductServiceInterface
  26. */
  27.  
  28. private $coreService;
  29.  
  30.  
  31.  
  32. /**
  33. * The previously existing core service.
  34. *
  35. * @var \Shopware\AtsdBundle\Bundle\StoreFrontBundle\BundleService
  36. */
  37.  
  38. private $bundleService;
  39.  
  40.  
  41.  
  42. /**
  43. * The previously existing core service.
  44. *
  45. * @var \Shopware\AtsdBundle\Components\AtsdBundle
  46. */
  47.  
  48. private $component;
  49.  
  50.  
  51.  
  52. /**
  53. * DI container.
  54. *
  55. * @var \Shopware\Components\DependencyInjection\Container
  56. */
  57.  
  58. protected $container;
  59.  
  60.  
  61.  
  62.  
  63.  
  64. /**
  65. * Object constructor.
  66. *
  67. * @param \Shopware\Bundle\StoreFrontBundle\Service\ListProductServiceInterface $coreService
  68. * @param \Shopware\AtsdBundle\Bundle\StoreFrontBundle\BundleService $bundleService
  69. * @param \Shopware\AtsdBundle\Components\AtsdBundle $component
  70. * @param \Shopware\Components\DependencyInjection\Container $container
  71. *
  72. * @return \Shopware\AtsdBundle\Bundle\StoreFrontBundle\ListProductService
  73. */
  74.  
  75. public function __construct(
  76. \Shopware\Bundle\StoreFrontBundle\Service\ListProductServiceInterface $coreService,
  77. \Shopware\AtsdBundle\Bundle\StoreFrontBundle\BundleService $bundleService,
  78. \Shopware\AtsdBundle\Components\AtsdBundle $component,
  79. \Shopware\Components\DependencyInjection\Container $container )
  80. {
  81. // set parameters
  82. $this->coreService = $coreService;
  83. $this->bundleService = $bundleService;
  84. $this->component = $component;
  85. $this->container = $container;
  86. }
  87.  
  88.  
  89.  
  90.  
  91.  
  92. /**
  93. * ...
  94. *
  95. * @param array $numbers
  96. * @param \Shopware\Bundle\StoreFrontBundle\Struct\ProductContextInterface $context
  97. *
  98. * @return \Shopware\Bundle\StoreFrontBundle\Struct\ListProduct[]
  99. */
  100.  
  101. public function getList( array $numbers, \Shopware\Bundle\StoreFrontBundle\Struct\ProductContextInterface $context )
  102. {
  103. // call core service
  104. $products = $this->coreService->getList( $numbers, $context );
  105.  
  106. // get all bundles
  107. $bundles = $this->bundleService->getList( $products );
  108.  
  109.  
  110.  
  111. // loop all products
  112. foreach ( $products as $product )
  113. {
  114. // we need an array to use ->get( "bundles" ) in the template
  115. $arr = ( isset( $bundles[$product->getId()] ) )
  116. ? $bundles[$product->getId()]
  117. : array();
  118.  
  119. // add attribute
  120. $product->addAttribute(
  121. "atsd_bundle",
  122. new \Shopware\Bundle\StoreFrontBundle\Struct\Attribute( array( 'bundles' => $arr ) )
  123. );
  124. }
  125.  
  126.  
  127.  
  128. // return the products
  129. return $products;
  130. }
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137. /**
  138. * ...
  139. *
  140. * @param string $number
  141. * @param \Shopware\Bundle\StoreFrontBundle\Struct\ProductContextInterface $context
  142. *
  143. * @return \Shopware\Bundle\StoreFrontBundle\Struct\ListProduct
  144. */
  145.  
  146. public function get( $number, \Shopware\Bundle\StoreFrontBundle\Struct\ProductContextInterface $context )
  147. {
  148. // call our list
  149. $products = $this->getList( array( $number ), $context );
  150.  
  151. // return first product
  152. return array_shift( $products );
  153. }
  154.  
  155.  
  156.  
  157.  
  158.  
  159. }
Advertisement
Add Comment
Please, Sign In to add comment