/**
  * Test getter/setter for category property
  */
 public function testGetSetCategory()
 {
     $this->assertNull($this->channel->getCategory());
     $expectedCategory = $this->createCategory('test-tree');
     $this->assertEntity($this->channel->setCategory($expectedCategory));
     $this->assertEquals($expectedCategory, $this->channel->getCategory());
 }
 function let(DocumentManager $manager, Channel $ecommerce, Channel $mobile, Locale $enUs, Locale $frFr, CategoryInterface $category, ChannelManager $channelManager, CategoryRepository $categoryRepository, ProductRepository $productRepository, QueryBuilder $ormQb, Builder $odmQb, Query $odmQuery, Cursor $cursor)
 {
     $enUs->getCode()->willReturn('en_US');
     $frFr->getCode()->willReturn('fr_FR');
     $ecommerce->getCode()->willReturn('ecommerce');
     $ecommerce->getLabel()->willReturn('ECommerce');
     $ecommerce->getLocales()->willReturn(array($enUs, $frFr));
     $ecommerce->getCategory()->willReturn($category);
     $mobile->getCode()->willReturn('mobile');
     $mobile->getLabel()->willReturn('Mobile');
     $mobile->getLocales()->willReturn(array($enUs));
     $mobile->getCategory()->willReturn($category);
     $odmQuery->execute()->willReturn($cursor);
     $productRepository->createQueryBuilder()->willReturn($odmQb);
     $odmQb->hydrate(Argument::any())->willReturn($odmQb);
     $odmQb->field(Argument::any())->willReturn($odmQb);
     $odmQb->in(Argument::any())->willReturn($odmQb);
     $odmQb->equals(Argument::any())->willReturn($odmQb);
     $odmQb->select('_id')->willReturn($odmQb);
     $odmQb->getQuery()->willReturn($odmQuery);
     $categoryRepository->getAllChildrenQueryBuilder($category, true)->willReturn($ormQb);
     $categoryRepository->getCategoryIds($category, $ormQb)->willReturn(array(1, 2, 3));
     $channelManager->getFullChannels()->willReturn(array($ecommerce, $mobile));
     $manager->getRepository('pim_product_class')->willReturn($productRepository);
     $this->beConstructedWith($manager, $channelManager, $categoryRepository, 'pim_product_class');
 }
 /**
  * Returns ready to export variant group products.
  *
  * @param Channel                                                    $channel
  * @param \Doctrine\Common\Collections\Collection|ProductInterface[] $products
  *
  * @return ProductInterface[]
  */
 public function apply(Channel $channel, $products)
 {
     $exportableProducts = [];
     $rootCategoryId = $channel->getCategory()->getId();
     foreach ($products as $product) {
         $productCategories = $product->getCategories()->toArray();
         if ($this->isProductComplete($product, $channel) && false !== $productCategories && $this->doesProductBelongToChannel($productCategories, $rootCategoryId)) {
             $exportableProducts[] = $product;
         }
     }
     return $exportableProducts;
 }
 /**
  * {@inheritdoc}
  */
 public function buildByChannelAndCompleteness(Channel $channel)
 {
     $scope = $channel->getCode();
     $qb = $this->buildByScope($scope);
     $rootAlias = $qb->getRootAlias();
     $expression = 'pCompleteness.product = ' . $rootAlias . ' AND ' . $qb->expr()->eq('pCompleteness.ratio', '100') . ' AND ' . $qb->expr()->eq('pCompleteness.channel', $channel->getId());
     $rootEntity = current($qb->getRootEntities());
     $completenessMapping = $this->_em->getClassMetadata($rootEntity)->getAssociationMapping('completenesses');
     $completenessClass = $completenessMapping['targetEntity'];
     $qb->innerJoin($completenessClass, 'pCompleteness', 'WITH', $expression);
     $treeId = $channel->getCategory()->getId();
     $expression = $qb->expr()->eq('pCategory.root', $treeId);
     $qb->innerJoin($rootAlias . '.categories', 'pCategory', 'WITH', $expression);
     return $qb;
 }
 function it_returns_only_products_in_the_given_channel(ProductInterface $product1, ProductInterface $product2, Channel $channel, ArrayCollection $productCategories1, ArrayCollection $productCategories2, ArrayCollection $completenesses, Category $rootCategory, Category $category1, Category $category2, AbstractCompleteness $completeness1, AbstractCompleteness $completeness2)
 {
     $channel->getCategory()->willReturn($rootCategory);
     $channel->getId()->willReturn(2);
     $rootCategory->getId()->willReturn(1);
     $product1->getCategories()->willReturn($productCategories1);
     $product2->getCategories()->willReturn($productCategories2);
     $product1->getCompletenesses()->willReturn($completenesses);
     $product2->getCompletenesses()->willReturn($completenesses);
     $completenesses->toArray()->willReturn([$completeness1, $completeness2]);
     $completeness1->getChannel()->willReturn($channel);
     $completeness2->getChannel()->willReturn($channel);
     $completeness1->getRatio()->willReturn(100);
     $completeness2->getRatio()->willReturn(100);
     $productCategories1->toArray()->willReturn([$category1]);
     $productCategories2->toArray()->willReturn([$category2]);
     $category1->getRoot()->willReturn(1);
     $category2->getRoot()->willReturn(5);
     $this->apply($channel, [$product1, $product2])->shouldReturn([$product1]);
 }
 /**
  * {@inheritdoc}
  */
 public function buildByChannelAndCompleteness(Channel $channel)
 {
     $qb = $this->createQueryBuilder('p');
     foreach ($channel->getLocales() as $locale) {
         $qb->addOr($qb->expr()->field(sprintf('normalizedData.completenesses.%s-%s', $channel->getCode(), $locale->getCode()))->equals(100));
     }
     $categoryIds = $this->categoryRepository->getAllChildrenIds($channel->getCategory());
     $qb->addAnd($qb->expr()->field('categoryIds')->in($categoryIds));
     return $qb;
 }
 /**
  * Returns category tree code
  *
  * @param Channel $channel
  *
  * @return string
  */
 protected function normalizeCategoryTree(Channel $channel)
 {
     return $channel->getCategory()->getCode();
 }
 /**
  * {@inheritDoc}
  */
 public function getCategory()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getCategory', array());
     return parent::getCategory();
 }