function it_normalizes_an_existing_product_into_mongodb_document($mongoFactory, $serializer, ProductInterface $product, \MongoId $mongoId, \MongoDate $mongoDate, Association $assoc1, Association $assoc2, CategoryInterface $category1, CategoryInterface $category2, Group $group1, Group $group2, AbstractProductValue $value1, AbstractProductValue $value2, Family $family)
 {
     $mongoFactory->createMongoId('product1')->willReturn($mongoId);
     $mongoFactory->createMongoDate()->willReturn($mongoDate);
     $family->getId()->willReturn(36);
     $category1->getId()->willReturn(12);
     $category2->getId()->willReturn(34);
     $group1->getId()->willReturn(56);
     $group2->getId()->willReturn(78);
     $product->getId()->willReturn('product1');
     $product->getCreated()->willReturn(null);
     $product->getFamily()->willReturn($family);
     $product->isEnabled()->willReturn(true);
     $product->getGroups()->willReturn([$group1, $group2]);
     $product->getCategories()->willReturn([$category1, $category2]);
     $product->getAssociations()->willReturn([$assoc1, $assoc2]);
     $product->getValues()->willReturn([$value1, $value2]);
     $context = ['_id' => $mongoId];
     $serializer->normalize($product, 'mongodb_json')->willReturn(['data' => 'data', 'completenesses' => 'completenesses']);
     $serializer->normalize($value1, 'mongodb_document', $context)->willReturn('my_value_1');
     $serializer->normalize($value2, 'mongodb_document', $context)->willReturn('my_value_2');
     $serializer->normalize($assoc1, 'mongodb_document', $context)->willReturn('my_assoc_1');
     $serializer->normalize($assoc2, 'mongodb_document', $context)->willReturn('my_assoc_2');
     $this->normalize($product, 'mongodb_document')->shouldReturn(['_id' => $mongoId, 'created' => $mongoDate, 'updated' => $mongoDate, 'family' => 36, 'enabled' => true, 'groupIds' => [56, 78], 'categoryIds' => [12, 34], 'associations' => ['my_assoc_1', 'my_assoc_2'], 'values' => ['my_value_1', 'my_value_2'], 'normalizedData' => ['data' => 'data'], 'completenesses' => []]);
 }
 function it_denormalizes_an_existing_group_with_properties($groupRepository, Group $group, GroupType $type, AttributeInterface $size, AttributeInterface $color, GroupTranslation $translationUS)
 {
     $groupRepository->findOneByIdentifier('tshirt')->willReturn(null);
     $group->getId()->willReturn(42);
     $group->setCode('tshirt')->shouldBeCalled();
     $group->setType(Argument::any())->shouldNotBeCalled();
     $group->setAttributes(Argument::any())->shouldNotBeCalled();
     $group->getTranslation('en_US')->willReturn($translationUS);
     $translationUS->setLabel('My T-shirt')->shouldBeCalled();
     $group->addTranslation($translationUS)->shouldBeCalled();
     $this->denormalize(['code' => 'tshirt', 'label-en_US' => 'My T-shirt'], self::ENTITY_CLASS, self::FORMAT_CSV, ['entity' => $group])->shouldReturn($group);
 }
 function let(WebserviceGuesser $webserviceGuesser, NormalizerGuesser $normalizerGuesser, LocaleManager $localeManager, MagentoMappingMerger $storeViewMappingMerger, CurrencyManager $currencyManager, ChannelManager $channelManager, MagentoMappingMerger $categoryMappingMerger, MagentoMappingMerger $attributeMappingMerger, GroupManager $groupManager, Webservice $webservice, MappingCollection $mappingCollection, ProductNormalizer $productNormalizer, GroupRepository $groupRepository, ConfigurableNormalizer $configurableNormalizer, Group $group, MagentoSoapClientParametersRegistry $clientParametersRegistry, MagentoSoapClientParameters $clientParameters)
 {
     $this->beConstructedWith($webserviceGuesser, $normalizerGuesser, $localeManager, $storeViewMappingMerger, $currencyManager, $channelManager, $categoryMappingMerger, $attributeMappingMerger, $groupManager, $clientParametersRegistry);
     $clientParametersRegistry->getInstance(null, null, null, '/api/soap/?wsdl', 'default', null, null)->willReturn($clientParameters);
     $webserviceGuesser->getWebservice($clientParameters)->willReturn($webservice);
     $storeViewMappingMerger->getMapping()->willReturn($mappingCollection);
     $normalizerGuesser->getProductNormalizer($clientParameters, null, 4, null)->willReturn($productNormalizer);
     $webservice->getStoreViewsList()->willReturn([['store_id' => '1', 'code' => 'default', 'website_id' => '1', 'group_id' => '1', 'name' => 'Default Store View', 'sort_order' => '0', 'is_active' => '1']]);
     $webservice->getAllAttributes()->willReturn(['name' => ['attribute_id' => '71', 'code' => 'name', 'type' => 'text', 'required' => '1', 'scope' => 'store']]);
     $webservice->getAllAttributesOptions()->willReturn([]);
     $categoryMappingMerger->getMapping()->willReturn($mappingCollection);
     $attributeMappingMerger->getMapping()->willReturn($mappingCollection);
     $normalizerGuesser->getConfigurableNormalizer($clientParameters, $productNormalizer, Argument::type('\\Pim\\Bundle\\MagentoConnectorBundle\\Manager\\PriceMappingManager'))->willReturn($configurableNormalizer);
     $groupManager->getRepository()->willReturn($groupRepository);
     $group->getId()->willReturn(1);
 }
 function let(ChannelManager $channelManager, ProductNormalizer $productNormalizer, PriceMappingManager $priceMappingManager, MappingCollection $categoryMapping, MappingCollection $attributeMapping, MappingCollection $storeViewMapping, ProductInterface $product, Channel $channel, Locale $localeFR, Locale $localeEN, Group $group, Attribute $attribute)
 {
     $this->beConstructedWith($channelManager, $productNormalizer, $priceMappingManager, 4);
     $this->globalContext = ['attributeSetId' => 0, 'magentoAttributes' => ['attribute_code' => ['attribute_id' => 42]], 'magentoAttributesOptions' => [], 'storeViewMapping' => $storeViewMapping, 'magentoStoreViews' => [['code' => 'fr_fr']], 'defaultLocale' => 'default_locale', 'website' => 'website', 'channel' => 'channel', 'categoryMapping' => $categoryMapping, 'attributeCodeMapping' => $attributeMapping, 'create' => true, 'defaultStoreView' => 'default', 'smallImageAttribute' => 'smallImageAttr', 'baseImageAttribute' => 'baseImageAttr', 'thumbnailAttribute' => 'thumbnailAttr', 'pimGrouped' => 'grouped_product_code', 'urlKey' => false, 'skuFirst' => false];
     $productNormalizer->getNormalizedImages($product, 'conf-group_code', 'smallImageAttr', 'baseImageAttr', 'thumbnailAttr')->willReturn([]);
     $productNormalizer->getValues(Argument::cetera())->willReturn([ProductNormalizer::URL_KEY => 'my-url-key']);
     $channelManager->getChannelByCode('channel')->willReturn($channel);
     $channel->getLocales()->willReturn([$localeEN, $localeFR]);
     $localeEN->getCode()->willReturn('default_locale');
     $localeFR->getCode()->willReturn('fr_FR');
     $channel->getCode()->willReturn('channel_code');
     $storeViewMapping->getTarget('default_locale')->willReturn('default_locale');
     $storeViewMapping->getTarget('fr_FR')->willReturn('fr_fr');
     $group->getId()->willReturn(44);
     $group->getCode()->willReturn('group_code');
     $product->getIdentifier()->willReturn('sku-000');
     $attribute->setCode('attribute_code');
     $group->getAttributes()->willReturn([$attribute]);
     $attribute->getCode()->willReturn('attribute_code');
     $attributeMapping->getTarget('attribute_code')->willReturn('attribute_code');
 }
 /**
  * {@inheritdoc}
  *
  * TODO: find a way to use param converter with interfaces
  *
  * @AclAncestor("pim_enrich_variant_group_edit")
  * @Template
  */
 public function editAction(Group $group)
 {
     if (!$group->getType()->isVariant()) {
         throw new NotFoundHttpException(sprintf('Variant group with id %d not found.', $group->getId()));
     }
     if ($this->groupHandler->process($group)) {
         $this->addFlash('success', 'flash.variant group.updated');
     }
     return ['form' => $this->groupForm->createView(), 'currentGroup' => $group->getId(), 'attributesForm' => $this->getAvailableAttributesForm($group)->createView()];
 }
 function it_normalizes_an_association_with_products_and_groups($mongoFactory, Association $assoc, AssociationType $assocType, \MongoId $mongoId, \MongoDBRef $ownerRef, ProductInterface $product1, \MongoDBRef $product1Ref, ProductInterface $product2, \MongoDBRef $product2Ref, Group $group1, Group $group2)
 {
     $assocType->getId()->willReturn(8);
     $assoc->getAssociationType()->willReturn($assocType);
     $context = ['_id' => '1234abc', 'collection_name' => 'product'];
     $mongoFactory->createMongoId()->willReturn($mongoId);
     $mongoFactory->createMongoDBRef('product', '1234abc')->willReturn($ownerRef);
     $mongoFactory->createMongoDBRef('product', 'product1')->willReturn($product1Ref);
     $mongoFactory->createMongoDBRef('product', 'product2')->willReturn($product2Ref);
     $product1->getId()->willReturn('product1');
     $product2->getId()->willReturn('product2');
     $assoc->getProducts()->willReturn([$product1, $product2]);
     $group1->getId()->willReturn(1);
     $group2->getId()->willReturn(2);
     $assoc->getGroups()->willReturn([$group1, $group2]);
     $this->normalize($assoc, 'mongodb_document', $context)->shouldReturn(['_id' => $mongoId, 'associationType' => 8, 'owner' => $ownerRef, 'products' => [$product1Ref, $product2Ref], 'groupIds' => [1, 2]]);
 }
 /**
  * {@inheritdoc}
  */
 public function findAllForVariantGroup(Group $variantGroup, array $criteria = array())
 {
     $qb = $this->createQueryBuilder()->eagerCursor(true);
     $qb->field('groupIds')->in([$variantGroup->getId()]);
     foreach ($criteria as $item) {
         $andExpr = $qb->expr()->field('values')->elemMatch(['attribute' => (int) $item['attribute']->getId(), 'option' => $item['option']->getId()]);
         $qb->addAnd($andExpr);
     }
     $cursor = $qb->getQuery()->execute();
     $products = [];
     foreach ($cursor as $product) {
         $products[] = $product;
     }
     return $products;
 }
 /**
  * Test getter for id property
  */
 public function testId()
 {
     $this->assertEmpty($this->group->getId());
 }
 function it_associates_only_products_in_channel_to_configurable($clientParametersRegistry, $normalizerGuesser, $groupManager, $channelManager, $productFilter, Group $group, Channel $channel, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, MagentoSoapClientParameters $clientParameters, WebserviceGuesser $webserviceGuesser, Webservice $webservice, ProductNormalizer $productNormalizer, ConfigurableNormalizer $configurableNormalizer, GroupRepository $groupRepository, StepExecution $stepExecution, EventDispatcher $eventDispatcher)
 {
     $clientParametersRegistry->getInstance(Argument::cetera())->willReturn($clientParameters);
     $webserviceGuesser->getWebservice($clientParameters)->willReturn($webservice);
     $normalizerGuesser->getProductNormalizer(Argument::cetera())->willReturn($productNormalizer);
     $normalizerGuesser->getConfigurableNormalizer(Argument::cetera())->willReturn($configurableNormalizer);
     $webservice->getStoreViewsList()->willReturn([['store_id' => '1', 'code' => 'default', 'website_id' => '1', 'group_id' => '1', 'name' => 'Default Store View', 'sort_order' => '0', 'is_active' => '1']]);
     $webservice->getAllAttributes()->willReturn(['name' => ['attribute_id' => '71', 'code' => 'name', 'type' => 'text', 'required' => '1', 'scope' => 'store']]);
     $webservice->getAllAttributesOptions()->willReturn([]);
     $webservice->getConfigurablesStatus([1 => ['group' => $group, 'products' => [$product1, $product2]]])->willReturn([['product_id' => '6', 'sku' => 'conf-groupCode', 'name' => 'foo', 'set' => '3', 'type' => 'configurable', 'category_ids' => ['7'], 'website_ids' => ['1']]]);
     $groupManager->getRepository()->willReturn($groupRepository);
     $groupRepository->getVariantGroupIds()->willReturn([1]);
     $channelManager->getChannelByCode('magento')->willReturn($channel);
     $channel->getId()->willReturn(3);
     $group->getId()->willReturn(1);
     $group->getProducts()->willReturn([$product1, $product2, $product3]);
     $group->getCode()->willReturn('groupCode');
     $product1->getGroups()->willReturn([$group]);
     $product1->getId()->willReturn(10);
     $product2->getId()->willReturn(11);
     $product3->getId()->willReturn(12);
     $productFilter->apply($channel, [$product1, $product2, $product3])->willReturn([$product1, $product2]);
     $configurableNormalizer->normalize(['group' => $group, 'products' => [$product1, $product2]], 'MagentoArray', Argument::type('array'))->shouldBeCalled();
     $this->setStepExecution($stepExecution);
     $this->setEventDispatcher($eventDispatcher);
     $this->setChannel('magento');
     $this->process([$product1]);
 }
 /**
  * {@inheritDoc}
  */
 public function getId()
 {
     if ($this->__isInitialized__ === false) {
         return (int) parent::getId();
     }
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', array());
     return parent::getId();
 }
 /**
  * Get matching products
  *
  * @param Group            $variantGroup the variant group
  * @param ProductInterface $entity       the product
  * @param array            $criteria     query criterias
  *
  * @return ProductInterface[]
  */
 protected function getMatchingProducts(Group $variantGroup, ProductInterface $entity = null, array $criteria = [])
 {
     if (!$variantGroup->getId()) {
         return [];
     }
     $repository = $this->manager->getProductRepository();
     $matchingProducts = $repository->findAllForVariantGroup($variantGroup, $criteria);
     if ($entity) {
         $matchingProducts = array_filter($matchingProducts, function ($product) use($entity) {
             return $product->getId() !== $entity->getId();
         });
     }
     return $matchingProducts;
 }