Advertisement
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 BundleService
- {
- /**
- * Shopware model manager.
- *
- * @var \Shopware\Components\Model\ModelManager
- */
- private $modelManager;
- /**
- * Plugin component.
- *
- * @var \Shopware\AtsdBundle\Components\AtsdBundle
- */
- private $component;
- /**
- * DI container.
- *
- * @var \Shopware\Components\DependencyInjection\Container
- */
- private $container;
- /**
- * Object constructor.
- *
- * @param \Shopware\Components\Model\ModelManager $modelManager
- * @param \Shopware\AtsdBundle\Components\AtsdBundle $component
- * @param \Shopware\Components\DependencyInjection\Container $container
- *
- * @return \Shopware\AtsdBundle\Bundle\StoreFrontBundle\BundleService
- */
- public function __construct(
- \Shopware\Components\Model\ModelManager $modelManager,
- \Shopware\AtsdBundle\Components\AtsdBundle $component,
- \Shopware\Components\DependencyInjection\Container $container )
- {
- // set parameters
- $this->modelManager = $modelManager;
- $this->component = $component;
- $this->container = $container;
- }
- /**
- * Get all bundles for the given products. The bundles are returned in an array
- * with the article id as key and the bundles as value.
- *
- * @param \Shopware\Bundle\StoreFrontBundle\Struct\ListProduct[] $products
- *
- * @return array
- */
- public function getList( array $products )
- {
- // get article ids
- $articleIds = $this->getArticleId( $products );
- // no articles given?
- if ( count( $articleIds ) == 0 )
- // done
- return array();
- // get query builder
- $builder = $this->component->getRepository()->getActiveBundlesWithArticlesQueryBuilder(
- $this->component->getCustomerGroup(),
- $this->component->getMainShop()
- );
- // only for our products
- $builder->andWhere(
- $builder->expr()->in( "article.id", $articleIds )
- );
- // get the results as array
- $bundles = $builder->getQuery()->getArrayResult();
- // return array with article id as key
- $return = array();
- // loop the bundles
- foreach ( $bundles as $bundle )
- {
- // does it even validate?
- if ( $this->component->validateBundle( $bundle, 1 ) == false )
- // ignore it
- continue;
- // get article id
- $id = $bundle['article']['id'];
- // not set?
- if ( !isset( $return[$id] ) )
- // set it
- $return[$id] = array();
- // add
- array_push( $return[$id], $bundle );
- }
- // return them
- return $return;
- }
- /**
- * ...
- *
- * @param array $products
- *
- * @return array
- */
- private function getArticleId( array $products )
- {
- // get the ids
- $articleIds = array_map(
- function( \Shopware\Bundle\StoreFrontBundle\Struct\ListProduct $product ) {
- return $product->getId();
- },
- $products
- );
- // unique the ids
- $articleIds = array_unique( array_values( $articleIds ) );
- // return them
- return $articleIds;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement