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' => []]); }
/** * Normalize the attributes * * @param Group $group * * @return array */ protected function normalizeAttributes(Group $group) { $attributes = array(); foreach ($group->getAttributes() as $attribute) { $attributes[] = $attribute->getCode(); } sort($attributes); return $attributes; }
/** * Bind products * * @param Group $group * @param array $appendProducts * @param array $removeProducts */ protected function bindProducts(Group $group, array $appendProducts, array $removeProducts) { foreach ($appendProducts as $product) { $group->addProduct($product); } foreach ($removeProducts as $product) { $group->removeProduct($product); } }
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); }
/** * {@inheritdoc} * * @Template * @AclAncestor("pim_enrich_group_create") */ public function createAction(Request $request) { if (!$request->isXmlHttpRequest()) { return $this->redirectToRoute('pim_enrich_variant_group_index'); } $groupType = $this->groupManager->getGroupTypeRepository()->findOneBy(array('code' => 'VARIANT')); $group = new Group(); $group->setType($groupType); if ($this->groupHandler->process($group)) { $this->addFlash('success', 'flash.variant group.created'); $url = $this->generateUrl('pim_enrich_variant_group_edit', array('id' => $group->getId())); $response = array('status' => 1, 'url' => $url); return new Response(json_encode($response)); } return array('form' => $this->groupForm->createView()); }
function let(ChannelManager $channelManager, ProductNormalizer $productNormalizer, PriceMappingManager $priceMappingManager, MappingCollection $categoryMapping, MappingCollection $attributeMapping, MappingCollection $storeViewMapping, ProductInterface $product, Channel $channel, Locale $localeFR, Locale $localeEN, Group $group) { $this->beConstructedWith($channelManager, $productNormalizer, $priceMappingManager, $attributeMapping); $this->globalContext = ['attributeSetId' => 0, 'magentoAttributes' => [], 'magentoAttributesOptions' => [], 'storeViewMapping' => $storeViewMapping, 'magentoStoreViews' => [['code' => 'fr_fr']], 'defaultLocale' => 'default_locale', 'website' => 'website', 'channel' => 'channel', 'categoryMapping' => $categoryMapping, 'attributeCodeMapping' => $attributeMapping, 'create' => true, 'defaultStoreView' => 'default']; $productNormalizer->getNormalizedImages($product, 'conf-group_code')->willReturn([]); $productNormalizer->getValues(Argument::cetera())->willReturn([]); $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->getCode()->willReturn('group_code'); $product->getIdentifier()->willReturn('sku-000'); }
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); }
/** * Get price mapping for the given group and products. * * @param Group $group * @param array $products * @param MappingCollection $attributeMapping * @param boolean $lowest * * @return array */ public function getPriceMapping(Group $group, array $products, MappingCollection $attributeMapping, $lowest = true) { $attributes = $group->getAttributes(); $basePrice = $this->getLimitPrice($products, $attributeMapping, [], $lowest); $sortedAttributes = $this->getSortedAttributes($attributes, $products, $basePrice, $attributeMapping, $lowest); $priceChanges = []; foreach ($sortedAttributes as $attribute) { $attributePriceMapping = $this->getAttributePriceMapping($attribute, $basePrice, $products, $priceChanges, $attributeMapping, $lowest); $priceChanges[$attributeMapping->getTarget($attribute->getCode())] = $attributePriceMapping; } if ($lowest) { try { $this->validatePriceMapping($products, $priceChanges, $basePrice, $attributeMapping); } catch (ComputedPriceNotMatchedException $e) { return $this->getPriceMapping($group, $products, $attributeMapping, false); } } ksort($priceChanges); return [ConfigurableNormalizer::PRICE_CHANGES => $priceChanges, ConfigurableNormalizer::BASE_PRICE => $basePrice]; }
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'); }
/** * Test getter/setter for translations property */ public function testTranslations() { $this->assertCount(0, $this->group->getTranslations()); // Change value and assert new $newTranslation = new GroupTranslation(); $this->assertEntity($this->group->addTranslation($newTranslation)); $this->assertCount(1, $this->group->getTranslations()); $this->assertInstanceOf('Pim\\Bundle\\CatalogBundle\\Entity\\GroupTranslation', $this->group->getTranslations()->first()); $this->group->addTranslation($newTranslation); $this->assertCount(1, $this->group->getTranslations()); $this->assertEntity($this->group->removeTranslation($newTranslation)); $this->assertCount(0, $this->group->getTranslations()); }
function let(Group $group, Product $product1, Product $product2, Product $product3, Attribute $attribute1, Attribute $attribute2, AttributeOption $attributeOption11, AttributeOption $attributeOption12, AttributeOption $attributeOption21, AttributeOption $attributeOption22, ProductValue $productValueOption11, ProductValue $productValueOption12, ProductValue $productValueOption21, ProductValue $productValueOption22, ProductValue $productValuePrice1, ProductPrice $productPrice1, ProductValue $productValuePrice2, ProductPrice $productPrice2, ProductValue $productValuePrice3, ProductPrice $productPrice3, MappingCollection $attributeMapping) { $this->beConstructedWith('locale', 'currency'); $group->getAttributes()->willReturn([$attribute1, $attribute2]); //get attribute options $attribute1->getOptions()->willReturn([$attributeOption11, $attributeOption12]); $attribute1->getCode()->willReturn('attribute_1'); $attributeOption11->getAttribute()->willReturn($attribute1); $attributeOption11->getCode()->willReturn('attribute_1_option_1'); $productValueOption11->getData()->willReturn($attributeOption11); $attributeOption12->getAttribute()->willReturn($attribute1); $attributeOption12->getCode()->willReturn('attribute_1_option_2'); $productValueOption12->getData()->willReturn($attributeOption12); $attribute2->getOptions()->willReturn([$attributeOption21, $attributeOption22]); $attribute2->getCode()->willReturn('attribute_2'); $attributeOption21->getAttribute()->willReturn($attribute2); $attributeOption21->getCode()->willReturn('attribute_2_option_1'); $productValueOption21->getData()->willReturn($attributeOption21); $attributeOption22->getAttribute()->willReturn($attribute2); $attributeOption22->getCode()->willReturn('attribute_2_option_2'); $productValueOption22->getData()->willReturn($attributeOption22); //Get product prices $product1->getValue('price', 'locale')->willReturn($productValuePrice1); $product1->getIdentifier()->willReturn('product_1'); $productValuePrice1->getPrice('currency')->willReturn($productPrice1); $productPrice1->getData()->willReturn(5.0); $product2->getValue('price', 'locale')->willReturn($productValuePrice2); $product2->getIdentifier()->willReturn('product_2'); $productValuePrice2->getPrice('currency')->willReturn($productPrice2); $productPrice2->getData()->willReturn(15.0); $product3->getValue('price', 'locale')->willReturn($productValuePrice3); $product3->getIdentifier()->willReturn('product_3'); $productValuePrice3->getPrice('currency')->willReturn($productPrice3); $productPrice3->getData()->willReturn(10.0); $attributeMapping->getSource('attribute_1')->willReturn('attribute_1'); $attributeMapping->getSource('attribute_2')->willReturn('attribute_2'); $attributeMapping->getTarget('attribute_1')->willReturn('attribute_1'); $attributeMapping->getTarget('attribute_2')->willReturn('attribute_2'); }
function it_normalizes_product_with_associations($filter, ProductInterface $product, AbstractAttribute $skuAttribute, AbstractProductValue $sku, Association $myCrossSell, AssociationType $crossSell, Association $myUpSell, AssociationType $upSell, Group $associatedGroup1, Group $associatedGroup2, ProductInterface $associatedProduct1, ProductInterface $associatedProduct2, AbstractProductValue $skuAssocProduct1, AbstractProductValue $skuAssocProduct2, Collection $values, Family $family, $serializer) { $family->getCode()->willReturn('shoes'); $skuAttribute->getCode()->willReturn('sku'); $skuAttribute->getAttributeType()->willReturn('pim_catalog_identifier'); $skuAttribute->isLocalizable()->willReturn(false); $skuAttribute->isScopable()->willReturn(false); $sku->getAttribute()->willReturn($skuAttribute); $sku->getData()->willReturn('sku-001'); $crossSell->getCode()->willReturn('cross_sell'); $myCrossSell->getAssociationType()->willReturn($crossSell); $myCrossSell->getGroups()->willReturn([]); $myCrossSell->getProducts()->willReturn([]); $upSell->getCode()->willReturn('up_sell'); $myUpSell->getAssociationType()->willReturn($upSell); $associatedGroup1->getCode()->willReturn('associated_group1'); $associatedGroup2->getCode()->willReturn('associated_group2'); $myUpSell->getGroups()->willReturn([$associatedGroup1, $associatedGroup2]); $skuAssocProduct1->getAttribute()->willReturn($skuAttribute); $skuAssocProduct2->getAttribute()->willReturn($skuAttribute); $skuAssocProduct1->__toString()->willReturn('sku_assoc_product1'); $skuAssocProduct2->__toString()->willReturn('sku_assoc_product2'); $associatedProduct1->getIdentifier()->willReturn($skuAssocProduct1); $associatedProduct2->getIdentifier()->willReturn($skuAssocProduct2); $myUpSell->getProducts()->willReturn([$associatedProduct1, $associatedProduct2]); $product->getIdentifier()->willReturn($sku); $product->getFamily()->willReturn($family); $product->isEnabled()->willReturn(true); $product->getGroupCodes()->willReturn('group1,group2,variant_group_1'); $product->getCategoryCodes()->willReturn('nice shoes, converse'); $product->getAssociations()->willReturn([$myCrossSell, $myUpSell]); $product->getValues()->willReturn($values); $filter->filter(Argument::cetera())->willReturn([$sku]); $serializer->normalize($sku, 'flat', Argument::any())->willReturn(['sku' => 'sku-001']); $this->normalize($product, 'flat', [])->shouldReturn(['sku' => 'sku-001', 'family' => 'shoes', 'groups' => 'group1,group2,variant_group_1', 'categories' => 'nice shoes, converse', 'cross_sell-groups' => '', 'cross_sell-products' => '', 'up_sell-groups' => 'associated_group1,associated_group2', 'up_sell-products' => 'sku_assoc_product1,sku_assoc_product2', 'enabled' => 1]); }
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} * * @return Group */ protected function createEntity(array $data) { $group = new Group(); $group->setCode($data['code']); $type = new GroupType(); $type->setCode($data['type']); $type->setVariant($data['type'] === 'VARIANT'); $group->setType($type); foreach ($this->getLabels($data) as $locale => $label) { $translation = $group->getTranslation($locale); $translation->setLabel($label); $group->addTranslation($translation); } foreach ($this->getAttributes($data) as $attribute) { $group->addAttribute($attribute); } return $group; }
/** * {@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; }
/** * Returns the attribute codes for a group * * @param Group $group * * @return array */ protected function getGroupAttributeCodes(Group $group) { $code = $group->getCode(); if (!isset($this->groupAttributeCodes[$code])) { $this->groupAttributeCodes[$code] = $this->getAttributeCodes($group); } return $this->groupAttributeCodes[$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()]; }
/** * Create a group entity * * @param string $code * * @return Group */ protected function createGroup($code) { $group = new Group(); $group->setCode($code); return $group; }
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]); }
function it_normalizes_group($normalizer, Group $group) { $group->getCode()->willReturn('mongo'); $normalizer->normalize($group, 'mongodb_json', [])->willReturn(['label' => 'translations']); $this->normalize($group, 'mongodb_json', [])->shouldReturn(['code' => 'mongo', 'label' => 'translations']); }
/** * {@inheritDoc} */ public function setProductTemplate(\Pim\Bundle\CatalogBundle\Model\ProductTemplateInterface $productTemplate) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setProductTemplate', array($productTemplate)); return parent::setProductTemplate($productTemplate); }
/** * @param string $code * @param string $label * @param string $type * @param array $attributes * @param array $products */ protected function createProductGroup($code, $label, $type, array $attributes, array $products = []) { $group = new Group(); $group->setCode($code); $group->setLocale('en_US')->setLabel($label); // TODO translation refactoring $type = $this->getGroupType($type); $group->setType($type); foreach ($attributes as $attributeCode) { $attribute = $this->getAttribute($attributeCode); $group->addAttribute($attribute); } // TODO replace by call to a saver $this->validate($group); $this->persist($group); $this->flush($group); foreach ($products as $sku) { if (!empty($sku)) { $product = $this->getProduct($sku); $product->addGroup($group); $this->validate($product); $this->getProductSaver()->save($product); } } }
/** * 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; }