function it_returns_filters_on_family_grid($massActionDispatcher, Request $request, FamilyInterface $family1, FamilyInterface $family2)
 {
     $request->get('gridName')->willReturn('family-grid');
     $massActionDispatcher->dispatch($request)->willReturn([$family1, $family2]);
     $family1->getId()->willReturn(45);
     $family2->getId()->willReturn(70);
     $massActionDispatcher->getRawFilters($request)->shouldNotBeCalled();
     $this->adapt($request)->shouldReturn([['field' => 'id', 'operator' => 'IN', 'value' => [45, 70]]]);
 }
 /**
  * {@inheritdoc}
  */
 public function getFullFamilies(FamilyInterface $family = null, ChannelInterface $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();
 }
 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, GroupInterface $group1, GroupInterface $group2, ProductValueInterface $value1, ProductValueInterface $value2, FamilyInterface $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' => []]);
 }
 /**
  * Schedule recalculation of completenesses for all product
  * of a family
  *
  * @param FamilyInterface $family
  */
 public function scheduleForFamily(FamilyInterface $family)
 {
     if ($family->getId()) {
         $this->generator->scheduleForFamily($family);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function findAllIdsForFamily(FamilyInterface $family)
 {
     $qb = $this->createQueryBuilder('p')->hydrate(false)->field('family')->equals($family->getId())->select('_id');
     $results = $qb->getQuery()->execute()->toArray();
     return array_keys($results);
 }
 function it_is_not_attribute_removable_with_family_containing_attribute(AttributeInterface $attribute, FamilyInterface $family, ArrayCollection $familyAttributes)
 {
     $familyAttributes->contains($attribute)->willReturn(true);
     $family->getId()->willReturn(42);
     $family->getAttributes()->willReturn($familyAttributes);
     $this->setFamily($family);
     $this->isAttributeRemovable($attribute)->shouldReturn(false);
 }
 /**
  * {@inheritdoc}
  */
 public function scheduleForFamily(FamilyInterface $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();
 }
 /**
  * {@inheritdoc}
  */
 public function findAttributesByFamily(FamilyInterface $family)
 {
     $qb = $this->createQueryBuilder('a');
     $qb->select('a, g')->join('a.group', 'g')->innerJoin('a.families', 'f', 'WITH', 'f.id = :family')->setParameter(':family', $family->getId());
     return $qb->getQuery()->getResult();
 }
 /**
  * @param FamilyInterface    $family
  * @param AttributeInterface $attribute
  * @param string             $channelCode
  *
  * @return AttributeRequirementInterface
  */
 protected function createAttributeRequirement(FamilyInterface $family, AttributeInterface $attribute, $channelCode)
 {
     $channel = $this->channelRepository->findOneByIdentifier($channelCode);
     if (null === $channel) {
         throw new \InvalidArgumentException(sprintf('Channel with "%s" code does not exist', $channelCode));
     }
     $requirement = $this->requirementRepo->findOneBy(['attribute' => $attribute->getId(), 'channel' => $channel->getId(), 'family' => $family->getId()]);
     if (null === $requirement) {
         $requirement = $this->attrRequiFactory->createAttributeRequirement($attribute, $channel, true);
     }
     return $requirement;
 }
 public function it_should_not_remove_identifier_requirements_when_other_requirements_are_provided($attrRequiFactory, $channelRepository, FamilyInterface $family, AttributeRepositoryInterface $attributeRepository, AttributeInterface $skuAttribute, AttributeInterface $nameAttribute, AttributeInterface $descAttribute, AttributeRequirementInterface $skuMobileRqrmt, AttributeRequirementInterface $skuPrintRqrmt, AttributeRequirementInterface $namePrintRqrmt, AttributeRequirementInterface $descPrintRqrmt, ChannelInterface $mobileChannel, ChannelInterface $printChannel)
 {
     $values = ['code' => 'mycode', 'requirements' => ['print' => ['name', 'description']]];
     $family->getAttributeRequirements()->willReturn([$skuMobileRqrmt, $skuPrintRqrmt]);
     $family->getId()->willReturn(42);
     $skuMobileRqrmt->getAttribute()->willReturn($skuAttribute);
     $skuPrintRqrmt->getAttribute()->willReturn($skuAttribute);
     $skuMobileRqrmt->getChannelCode()->willReturn('mobile');
     $skuPrintRqrmt->getChannelCode()->willReturn('print');
     $skuAttribute->getAttributeType()->willReturn(AttributeTypes::IDENTIFIER);
     $channelRepository->findOneByIdentifier('print')->willReturn($printChannel);
     $attributeRepository->findOneByIdentifier('name')->willReturn($nameAttribute);
     $attributeRepository->findOneByIdentifier('description')->willReturn($descAttribute);
     $attrRequiFactory->createAttributeRequirement($nameAttribute, $printChannel, true)->willReturn($namePrintRqrmt);
     $attrRequiFactory->createAttributeRequirement($descAttribute, $printChannel, true)->willReturn($descPrintRqrmt);
     $namePrintRqrmt->getAttribute()->willReturn($nameAttribute);
     $descPrintRqrmt->getAttribute()->willReturn($descAttribute);
     $channelRepository->getChannelCodes()->willReturn(['mobile', 'print']);
     $channelRepository->findOneByIdentifier('mobile')->willReturn($mobileChannel);
     $channelRepository->findOneByIdentifier('print')->willReturn($printChannel);
     $attributeRepository->getIdentifier()->willReturn($skuAttribute);
     $family->setCode('mycode')->shouldBeCalled();
     $family->setAttributeRequirements([$skuMobileRqrmt, $skuPrintRqrmt, $namePrintRqrmt, $descPrintRqrmt])->shouldBeCalled();
     $this->update($family, $values, []);
 }
 /**
  * {@inheritdoc}
  */
 public function scheduleForFamily(FamilyInterface $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 setFamily(FamilyInterface $family = null)
 {
     if (null !== $family) {
         $this->familyId = $family->getId();
     }
     $this->family = $family;
     return $this;
 }