/**
  * Test getter/setter for code property
  */
 public function testGetSetCode()
 {
     $this->assertEmpty($this->channel->getCode());
     // change value and assert new
     $newCode = 'ecommerce';
     $this->assertEntity($this->channel->setCode($newCode));
     $this->assertEquals($newCode, $this->channel->getCode());
 }
 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');
 }
 function it_normalizes_completeness(Completeness $completeness, Channel $channel, Locale $locale)
 {
     $channel->getCode()->willReturn('ecommerce');
     $locale->getCode()->willReturn('en_US');
     $completeness->getChannel()->willReturn($channel);
     $completeness->getLocale()->willReturn($locale);
     $completeness->getRatio()->willReturn(42);
     $this->normalize($completeness, 'mongodb_json', [])->shouldReturn(["ecommerce-en_US" => 42]);
 }
 function it_generates_a_query_to_update_product_scopable_attributes($namingUtility, AbstractAttribute $label, Channel $mobile)
 {
     $namingUtility->getScopableAttributes(false)->willReturn([$label]);
     $label->getCode()->willReturn('label');
     $namingUtility->getLocaleCodes()->willReturn(['fr_FR', 'en_US']);
     $namingUtility->appendSuffixes(['normalizedData.label'], ['fr_FR', 'en_US'])->willReturn(['normalizedData.label-fr_FR', 'normalizedData.label-en_US']);
     $namingUtility->appendSuffixes(['normalizedData.label-fr_FR', 'normalizedData.label-en_US'], ['mobile'])->willReturn(['normalizedData.label-fr_FR-mobile', 'normalizedData.label-en_US-mobile']);
     $mobile->getCode()->willReturn('mobile');
     $this->generateQuery($mobile, '', '', '')->shouldReturn([[['normalizedData.label-fr_FR-mobile' => ['$exists' => true]], ['$unset' => ['normalizedData.label-fr_FR-mobile' => '']], ['multiple' => true]], [['normalizedData.label-en_US-mobile' => ['$exists' => true]], ['$unset' => ['normalizedData.label-en_US-mobile' => '']], ['multiple' => true]]]);
 }
 /**
  * {@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_generates_localizable_indexes_when_saving_enabled_locale($collection, $namingUtility, AbstractAttribute $description, Locale $en_US, Locale $de_DE, Channel $ecommerce)
 {
     $description->getCode()->willReturn('description');
     $description->getBackendType()->willReturn('varchar');
     $description->isLocalizable()->willReturn(true);
     $description->isScopable()->willReturn(false);
     $description->isUseableAsGridFilter()->willReturn(true);
     $description->getAttributeType()->willReturn('pim_catalog_text');
     $en_US->getCode()->willReturn('en_US');
     $en_US->isActivated()->willReturn(true);
     $de_DE->getCode()->willReturn('de_DE');
     $de_DE->isActivated()->willReturn(true);
     $ecommerce->getCode()->willReturn('ecommerce');
     $ecommerce->getLocales()->willReturn([$en_US, $de_DE]);
     $namingUtility->getChannels()->willReturn([$ecommerce]);
     $namingUtility->getLocalizableAttributes()->willReturn([$description]);
     $namingUtility->getAttributeNormFields($description)->willReturn(['normalizedData.description-en_US', 'normalizedData.description-de_DE']);
     $options = ['background' => true, 'w' => 0];
     $collection->ensureIndex(['normalizedData.completenesses.ecommerce-en_US' => 1], $options)->shouldBeCalled();
     $collection->ensureIndex(['normalizedData.completenesses.ecommerce-de_DE' => 1], $options)->shouldBeCalled();
     $collection->ensureIndex(['normalizedData.description-en_US' => 1], $options)->shouldBeCalled();
     $collection->ensureIndex(['normalizedData.description-de_DE' => 1], $options)->shouldBeCalled();
     $this->ensureIndexesFromLocale($en_US);
 }
 /**
  * {@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;
 }
 function it_removes_obsolete_scopable_indexes_when_channel_removed($collection, Channel $ecommerce)
 {
     $ecommerce->getCode()->willReturn('ecommerce');
     $collection->getIndexInfo()->willReturn([["key" => ["_id" => 1]], ["key" => ["normalizedData.title-ecommerce-en_US" => 1]], ["key" => ["normalizedData.title-ecommerce-de_DE" => 1]], ["key" => ["normalizedData.title-mobile-de_DE" => 1]], ["key" => ["normalizedData.manufacturer_title" => 1]], ["key" => ["normalizedData.title_left-en_US" => 1]], ["key" => ["normalizedData.title_left-de_DE" => 1]], ["key" => ["normalizedData.price-ecommerce.EUR.data" => 1]], ["key" => ["normalizedData.price-mobile.USD.data" => 1]], ["key" => ["normalizedData.name-mobile" => 1]], ["key" => ["normalizedData.name-ecommerce" => 1]], ["key" => ["normalizedData.mobile_support.id" => 1]], ["key" => ["normalizedData.color-ecommerce.id" => 1]], ["key" => ["normalizedData.completenesses-ecommerce-en_US" => 1]], ["key" => ["normalizedData.completenesses-ecommerce-de_DE" => 1]]]);
     $collection->deleteIndex('normalizedData.title-ecommerce-en_US')->shouldBeCalled();
     $collection->deleteIndex('normalizedData.title-ecommerce-de_DE')->shouldBeCalled();
     $collection->deleteIndex('normalizedData.price-ecommerce.EUR.data')->shouldBeCalled();
     $collection->deleteIndex('normalizedData.name-ecommerce')->shouldBeCalled();
     $collection->deleteIndex('normalizedData.color-ecommerce.id')->shouldBeCalled();
     $collection->deleteIndex('normalizedData.completenesses-ecommerce-en_US')->shouldBeCalled();
     $collection->deleteIndex('normalizedData.completenesses-ecommerce-de_DE')->shouldBeCalled();
     $this->purgeIndexesFromChannel($ecommerce);
 }
 /**
  * Update catalog scope of users using a channel that will be removed
  *
  * @param Channel $channel
  *
  * @return null
  */
 protected function onChannelRemoved(Channel $channel)
 {
     $users = $this->findUsersBy(array('catalogScope' => $channel));
     $scopes = $this->container->get('pim_catalog.manager.channel')->getChannels();
     $defaultScope = current(array_filter($scopes, function ($scope) use($channel) {
         return $scope->getCode() !== $channel->getCode();
     }));
     foreach ($users as $user) {
         $user->setCatalogScope($defaultScope);
         $this->computeChangeset($user);
     }
 }
예제 #10
0
 /**
  * Remove indexes associated with the provided channel
  *
  * @param Channel $channel
  */
 public function purgeIndexesFromChannel(Channel $channel)
 {
     $channelPattern = sprintf('/^%s\\..+-%s/', ProductQueryUtility::NORMALIZED_FIELD, $channel->getCode());
     $indexesToRemove = $this->getIndexesMatching($channelPattern);
     $this->removeIndexes($indexesToRemove);
 }
 /**
  * Apply complete filter
  *
  * @param ProductQueryBuilder $pqb
  * @param Channel             $channel
  */
 protected function applyCompleteFilter(ProductQueryBuilder $pqb, Channel $channel)
 {
     switch ($this->completeCondition) {
         case "onlyComplete":
             $pqb->addFilter('completeness_for_export', '=', 100, ['scope' => $channel->getCode()]);
             break;
         case "onlyUncomplete":
             $pqb->addFilter('completeness_for_export', '<', 100, ['scope' => $channel->getCode()]);
             break;
     }
 }
 /**
  * Get the completeness fields for the channel
  *
  * @param Channel $channel
  *
  * @return array
  */
 protected function getCompletenessNormFields(Channel $channel = null)
 {
     $normFields = [];
     $channels = [];
     if (null === $channel) {
         $channels = $this->namingUtility->getChannels();
     } else {
         $channels[] = $channel;
     }
     foreach ($channels as $channel) {
         foreach ($channel->getLocales() as $locale) {
             $normFields[] = sprintf('%s.completenesses.%s-%s', ProductQueryUtility::NORMALIZED_FIELD, $channel->getCode(), $locale->getCode());
         }
     }
     return $normFields;
 }
 /**
  * Get channel code
  *
  * @return string
  */
 public function getChannelCode()
 {
     return $this->channel->getCode();
 }
 /**
  * {@inheritdoc}
  */
 public function scheduleForChannelAndLocale(Channel $channel, Locale $locale)
 {
     $productQb = $this->documentManager->createQueryBuilder($this->productClass);
     $pullExpr = $productQb->expr()->addAnd($productQb->expr()->field('channel')->equals($channel->getId()))->addAnd($productQb->expr()->field('locale')->equals($locale->getId()));
     $productQb->update()->multiple(true)->field(sprintf('normalizedData.completenesses.%s-%s', $channel->getCode(), $locale->getCode()))->unsetField()->field('completenesses')->pull($pullExpr)->getQuery()->execute();
 }
 /**
  * {@inheritDoc}
  */
 public function getCode()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getCode', array());
     return parent::getCode();
 }