Ejemplo n.º 1
0
 function it_creates_new_product_from_archetype(FactoryInterface $factory, ProductInterface $product, RepositoryInterface $archetypeRepository, ArchetypeBuilderInterface $archetypeBuilder, ArchetypeInterface $archetype)
 {
     $factory->createNew()->willReturn($product);
     $archetypeRepository->findOneBy(['code' => 'book'])->willReturn($archetype);
     $product->setArchetype($archetype)->shouldBeCalled();
     $archetypeBuilder->build($product)->shouldBeCalled();
     $this->createFromArchetype('book')->shouldReturn($product);
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function createFromArchetype($archetypeCode)
 {
     if (null === ($archetype = $this->archetypeRepository->findOneBy(array('code' => $archetypeCode)))) {
         throw new \InvalidArgumentException(sprintf('Requested archetype does not exist with code "%s".', $archetypeCode));
     }
     $product = $this->createNew();
     $product->setArchetype($archetype);
     $this->archetypeBuilder->build($product);
     return $product;
 }
 function it_updates_products_with_newer_attributes_added_to_their_archetypes(GenericEvent $event, ArchetypeInterface $archetype, ArchetypeBuilderInterface $builder, ObjectRepository $productRepository, ObjectManager $productManager, ProductInterface $productA, ProductInterface $productB)
 {
     $event->getSubject()->willReturn($archetype);
     $productRepository->findBy(array('archetype' => $archetype))->willReturn(array($productA, $productB));
     $builder->build($productA)->shouldBeCalled();
     $builder->build($productB)->shouldBeCalled();
     $productManager->persist($productA)->shouldBeCalled();
     $productManager->persist($productB)->shouldBeCalled();
     $this->onArchetypeUpdate($event);
 }
Ejemplo n.º 4
0
 function it_creates_new_product_from_archetype(FactoryInterface $factory, ProductInterface $product, RepositoryInterface $archetypeRepository, ArchetypeBuilderInterface $archetypeBuilder, ArchetypeInterface $archetype, VariantInterface $variant, FactoryInterface $variantFactory)
 {
     $variantFactory->createNew()->willReturn($variant);
     $variant->setMaster(true)->shouldBeCalled();
     $product->setMasterVariant($variant)->shouldBeCalled();
     $factory->createNew()->willReturn($product);
     $archetypeRepository->findOneBy(array('code' => 'book'))->willReturn($archetype);
     $product->setArchetype($archetype)->shouldBeCalled();
     $archetypeBuilder->build($product)->shouldBeCalled();
     $this->createFromArchetype('book')->shouldReturn($product);
 }
Ejemplo n.º 5
0
 /**
  * @param GenericEvent $event
  */
 public function onArchetypeUpdate(GenericEvent $event)
 {
     $archetype = $event->getSubject();
     if (!$archetype instanceof ArchetypeInterface) {
         throw new UnexpectedTypeException($archetype, ArchetypeInterface::class);
     }
     $products = $this->productRepository->findBy(array('archetype' => $archetype));
     foreach ($products as $product) {
         $this->builder->build($product);
         $this->productManager->persist($product);
     }
 }