Ejemplo n.º 1
0
 function it_has_family(Family $family)
 {
     $family->getId()->willReturn(42);
     $this->setFamily($family);
     $this->getFamily()->shouldReturn($family);
     $this->getFamilyId()->shouldReturn(42);
 }
 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' => []]);
 }
 /**
  * @param Family $family
  *
  * @Given /^I should be on the ("([^"]*)" family) page$/
  */
 public function iShouldBeOnTheFamilyPage(Family $family)
 {
     $expectedAddress = $this->getPage('Family edit')->getUrl(['id' => $family->getId()]);
     $this->assertAddress($expectedAddress);
 }
 /**
  * {@inheritDoc}
  */
 public function getId()
 {
     if ($this->__isInitialized__ === false) {
         return (int) parent::getId();
     }
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', array());
     return parent::getId();
 }
Ejemplo n.º 5
0
 /**
  * Test getter for id property
  */
 public function testId()
 {
     $this->assertEmpty($this->family->getId());
 }
 /**
  * Set family
  *
  * @param Family $family
  *
  * @return AbstractProduct
  */
 public function setFamily(Family $family = null)
 {
     if (null !== $family) {
         $this->familyId = $family->getId();
     }
     $this->family = $family;
     return $this;
 }
 /**
  * Add attributes to a family
  *
  * @param Family $family
  *
  * @AclAncestor("pim_enrich_family_edit_attributes")
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function addAttributesAction(Family $family)
 {
     $availableAttributes = new AvailableAttributes();
     $attributesForm = $this->getAvailableAttributesForm($family->getAttributes()->toArray(), $availableAttributes);
     $attributesForm->submit($this->getRequest());
     foreach ($availableAttributes->getAttributes() as $attribute) {
         $family->addAttribute($attribute);
     }
     $this->getManagerForClass('PimCatalogBundle:Family')->flush();
     $this->addFlash('success', 'flash.family.attributes added');
     return $this->redirectToRoute('pim_enrich_family_edit', array('id' => $family->getId()));
 }
 /**
  * @param Family $family
  *
  * @return string[]
  */
 public function findAllIdsForFamily(Family $family)
 {
     $qb = $this->createQueryBuilder('p')->hydrate(false)->field('family')->equals($family->getId())->select('_id');
     $results = $qb->getQuery()->execute()->toArray();
     return array_keys($results);
 }
 /**
  * Schedule recalculation of completenesses for all product
  * of a family
  *
  * @param Family $family
  */
 public function scheduleForFamily(Family $family)
 {
     if ($family->getId()) {
         $this->generator->scheduleForFamily($family);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function scheduleForFamily(Family $family)
 {
     $productQb = $this->documentManager->createQueryBuilder($this->productClass);
     $productQb->update()->multiple(true)->field('family')->equals($family->getId())->field('completenesses')->unsetField()->field('normalizedData.completenesses')->unsetField()->getQuery()->execute();
 }
 /**
  * {@inheritdoc}
  */
 public function scheduleForFamily(Family $family)
 {
     $sql = '
         DELETE c FROM pim_catalog_completeness c
           JOIN %product_table% p ON p.id = c.product_id
          WHERE p.family_id = :family_id';
     $sql = $this->applyTableNames($sql);
     $stmt = $this->connection->prepare($sql);
     $stmt->bindValue('family_id', $family->getId());
     $stmt->execute();
 }
 /**
  * Returns all families code with their required attributes code
  * Requirements can be restricted to a channel.
  *
  * @param Family  $family
  * @param Channel $channel
  *
  * @return array
  */
 public function getFullFamilies(Family $family = null, Channel $channel = null)
 {
     $qb = $this->createQueryBuilder('f')->select('f, c, l, r, a, cu')->join('f.requirements', 'r')->join('r.attribute', 'a')->join('r.channel', 'c')->join('c.locales', 'l')->join('c.currencies', 'cu')->where('r.required = 1');
     if (null !== $channel) {
         $qb->andWhere('r.channel = :channel')->setParameter('channel', $channel);
     }
     if (null !== $family) {
         $qb->andWhere('f.id = :familyId')->setParameter('familyId', $family->getId());
     }
     return $qb->getQuery()->getResult();
 }