Ejemplo n.º 1
0
 /**
  * Test getter/setter/add/remove for products property
  */
 public function testGetSetAddRemoveProducts()
 {
     // Change value and assert new
     $newProduct = new Product();
     $this->assertEntity($this->group->addProduct($newProduct));
     $this->assertInstanceOf('Pim\\Bundle\\CatalogBundle\\Model\\Product', $this->group->getProducts()->first());
     $this->assertEntity($this->group->removeProduct($newProduct));
     $this->assertNotInstanceOf('Pim\\Bundle\\CatalogBundle\\Model\\Product', $this->group->getProducts()->first());
     $this->assertCount(0, $this->group->getProducts());
     // Use setter and assert getProducts result
     $newProduct1 = new Product();
     $expectedProducts = array($newProduct, $newProduct1);
     $this->assertEntity($this->group->setProducts($expectedProducts));
     $this->assertCount(2, $this->group->getProducts());
 }
 /**
  * Validate variant group
  *
  * @param Group      $variantGroup
  * @param Constraint $constraint
  */
 protected function validateVariantGroup(Group $variantGroup, Constraint $constraint)
 {
     $existingCombinations = array();
     $products = $variantGroup->getProducts();
     if (null === $products) {
         $products = $this->getMatchingProducts($variantGroup);
     }
     foreach ($products as $product) {
         $values = array();
         foreach ($variantGroup->getAttributes() as $attribute) {
             $code = $attribute->getCode();
             $option = $product->getValue($code) ? (string) $product->getValue($code)->getOption() : '';
             $values[] = sprintf('%s: %s', $code, $option);
         }
         $combination = implode(', ', $values);
         if (in_array($combination, $existingCombinations)) {
             $this->addViolation($constraint, $variantGroup->getLabel(), $combination);
         } else {
             $existingCombinations[] = $combination;
         }
     }
 }
 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 getProducts()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getProducts', array());
     return parent::getProducts();
 }