function it_hydrates_a_result_record(Builder $builder, Query $query, ProductInterface $product, Association $association, AssociationType $associationType, ProductInterface $associatedProduct1, ProductInterface $associatedProduct2, ArrayCollection $productsCollection, ArrayCollection $productIdsCollection, ArrayIterator $productsIterator, ArrayCollection $associationsCollection, ArrayIterator $associationsIterator, ArrayIterator $arrayIterator)
 {
     $product->getId()->willReturn('110ae6b98ead0ee8778b46bb');
     $options = ['locale_code' => 'en_US', 'scope_code' => 'print', 'current_group_id' => null, 'attributes_configuration' => [], 'association_type_id' => 1, 'current_product' => $product];
     $builder->find()->willReturn($builder);
     $builder->count()->willReturn($builder);
     $builder->getQuery()->willReturn($query);
     $builder->hydrate(false)->willReturn($builder);
     $builder->setQueryArray(Argument::any())->willReturn($builder);
     $builder->limit(Argument::any())->willReturn($builder);
     $builder->skip(Argument::any())->willReturn($builder);
     $product->getAssociations()->willReturn($associationsCollection);
     $associationsCollection->getIterator()->willReturn($associationsIterator);
     $associationsIterator->rewind()->shouldBeCalled();
     $associationsCount = 1;
     $associationsIterator->valid()->will(function () use(&$associationsCount) {
         return $associationsCount-- > 0;
     });
     $associationsIterator->next()->shouldBeCalled();
     $associationsIterator->current()->will(new ReturnPromise([$association]));
     $associationsCollection->filter(Argument::any())->willReturn($associationsIterator);
     $associationsIterator->first()->willReturn($association);
     $association->getAssociationType()->willReturn($associationType);
     $associationType->getId()->willReturn(1);
     $associatedProduct1->getId()->willReturn('220ae6b98ead0ed7778b46bb');
     $associatedProduct2->getId()->willReturn('330ae6b98abd0ec8778b46bb');
     $association->getProducts()->willReturn($productsCollection);
     $productsCollection->getIterator()->willReturn($productsIterator);
     $productsIterator->rewind()->shouldBeCalled();
     $productsCount = 2;
     $productsIterator->valid()->will(function () use(&$productsCount) {
         return $productsCount-- > 0;
     });
     $associatedProduct1->getId()->willReturn('220ae6b98ead0ed7778b46bb');
     $associatedProduct2->getId()->willReturn('330ae6b98abd0ec8778b46bb');
     $association->getProducts()->willReturn($productsCollection);
     $productsCollection->getIterator()->willReturn($productsIterator);
     $productsIterator->rewind()->shouldBeCalled();
     $productsCount = 2;
     $productsIterator->valid()->will(function () use(&$productsCount) {
         return $productsCount-- > 0;
     });
     $productsIterator->next()->shouldBeCalled();
     $productsIterator->current()->will(new ReturnPromise([$associatedProduct1, $associatedProduct2]));
     $productsCollection->map(Argument::any())->willReturn($productIdsCollection);
     $productIdsCollection->toArray()->willReturn(['220ae6b98ead0ed7778b46bb', '330ae6b98abd0ec8778b46bb']);
     $queryDefinition = ['type' => 1, 'sort' => ['normalizedData.is_associated' => -1, '_id' => 1], 'limit' => 10, 'skip' => 0, 'query' => ['_id' => ['$ne' => \MongoId::__set_state(['$id' => '110ae6b98ead0ee8778b46bb'])]], 'newObj' => []];
     $query->getQuery()->willReturn($queryDefinition);
     $fixture = ['_id' => \MongoId::__set_state(['$id' => '550ae6b98ead0ee8778b46bb']), 'normalizedData' => [], 'sku' => ['attribute' => ['code' => 'sku', 'attributeType' => 'text', 'backendType' => 'text'], 'locale' => null, 'scope' => null, 'value' => 'mysku'], 'name' => ['attribute' => ['code' => 'name', 'attributeType' => 'text', 'backendType' => 'text'], 'locale' => 'fr_FR', 'scope' => null], 'desc' => ['attribute' => ['code' => 'desc', 'attributeType' => 'text', 'backendType' => 'text'], 'locale' => 'fr_FR', 'scope' => 'print'], 'is_associated' => 1];
     $query->execute()->willReturn($arrayIterator);
     $arrayIterator->toArray()->willReturn([$fixture]);
     $rows = $this->hydrate($builder, $options);
     $rows->shouldHaveCount(1);
     $firstResult = $rows[0];
     $firstResult->shouldBeAnInstanceOf('\\Oro\\Bundle\\DataGridBundle\\Datasource\\ResultRecord');
 }
 function it_massively_insert_new_products_and_update_existing_products($documentManager, $collection, $normalizer, $mongoFactory, $pendingPersister, $eventDispatcher, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, ProductInterface $product4)
 {
     $mongoFactory->createMongoId()->willReturn('my_mongo_id');
     $product1->getId()->willReturn("my_product_1");
     $product2->getId()->willReturn(null);
     $product3->getId()->willReturn("my_product_3");
     $product4->getId()->willReturn(null);
     $product1->setId(Argument::any())->shouldNotBeCalled();
     $product2->setId('my_mongo_id')->shouldBeCalled();
     $product3->setId(Argument::any())->shouldNotBeCalled();
     $product4->setId('my_mongo_id')->shouldBeCalled();
     $normalizer->normalize($product1, 'mongodb_document', ['collection_name' => 'pim_product_collection'])->willReturn(['_id' => 'my_product_1', 'normalized_product_1']);
     $normalizer->normalize($product2, 'mongodb_document', ['collection_name' => 'pim_product_collection'])->willReturn(['_id' => 'my_mongo_id', 'normalized_product_2']);
     $normalizer->normalize($product3, 'mongodb_document', ['collection_name' => 'pim_product_collection'])->willReturn(['_id' => 'my_product_3', 'normalized_product_3']);
     $normalizer->normalize($product4, 'mongodb_document', ['collection_name' => 'pim_product_collection'])->willReturn(['_id' => 'my_mongo_id', 'normalized_product_4']);
     $collection->batchInsert([['_id' => 'my_mongo_id', 'normalized_product_2'], ['_id' => 'my_mongo_id', 'normalized_product_4']])->shouldBeCalled();
     $collection->update(['_id' => 'my_product_1'], ['_id' => 'my_product_1', 'normalized_product_1'])->shouldBeCalled();
     $collection->update(['_id' => 'my_product_3'], ['_id' => 'my_product_3', 'normalized_product_3'])->shouldBeCalled();
     $pendingPersister->persistPendingVersions([$product1, $product2, $product3, $product4])->shouldBeCalled();
     $eventDispatcher->dispatch('pim_base_connector.direct_to_db_writer.pre_insert', Argument::any())->shouldBeCalled();
     $eventDispatcher->dispatch('pim_base_connector.direct_to_db_writer.pre_update', Argument::any())->shouldBeCalled();
     $eventDispatcher->dispatch('pim_base_connector.direct_to_db_writer.post_insert', Argument::any())->shouldBeCalled();
     $eventDispatcher->dispatch('pim_base_connector.direct_to_db_writer.post_update', Argument::any())->shouldBeCalled();
     $documentManager->clear()->shouldBeCalled();
     $this->write([$product1, $product2, $product3, $product4]);
 }
 function it_normalizes_groups($normalizer, $structureVersionProvider, $versionManager, $versionNormalizer, $localizedConverter, GroupInterface $tshirt, GroupTypeInterface $groupType, Version $oldestLog, Version $newestLog, ArrayCollection $products, ProductInterface $product, \ArrayIterator $productsIterator)
 {
     $options = ['decimal_separator' => ',', 'date_format' => 'dd/MM/yyyy'];
     $tshirt->getType()->willReturn($groupType);
     $groupType->isVariant()->willReturn(true);
     $variantNormalized = ['code' => 'my_variant', 'axis' => ['color', 'size'], 'type' => 'variant', 'values' => ['number' => ['data' => 12.5, 'locale' => null, 'scope' => null], 'metric' => ['data' => 12.5, 'locale' => null, 'scope' => null], 'prices' => ['data' => 12.5, 'locale' => null, 'scope' => null], 'date' => ['data' => '2015-01-31', 'locale' => null, 'scope' => null]]];
     $valuesLocalized = ['number' => ['data' => '12,5000', 'locale' => null, 'scope' => null], 'metric' => ['data' => '12,5000', 'locale' => null, 'scope' => null], 'prices' => ['data' => '12,50', 'locale' => null, 'scope' => null], 'date' => ['data' => '31/01/2015', 'locale' => null, 'scope' => null]];
     $normalizer->normalize($tshirt, 'json', $options)->willReturn($variantNormalized);
     $localizedConverter->convertToLocalizedFormats($variantNormalized['values'], $options)->willReturn($valuesLocalized);
     $structureVersionProvider->getStructureVersion()->willReturn(1);
     $versionManager->getOldestLogEntry($tshirt)->willReturn($oldestLog);
     $versionManager->getNewestLogEntry($tshirt)->willReturn($newestLog);
     $versionNormalizer->normalize($oldestLog, 'internal_api')->willReturn('normalized_oldest_log');
     $versionNormalizer->normalize($newestLog, 'internal_api')->willReturn('normalized_newest_log');
     $products->getIterator()->willReturn($productsIterator);
     $productsIterator->rewind()->shouldBeCalled();
     $productsCount = 1;
     $productsIterator->valid()->will(function () use(&$productsCount) {
         return $productsCount-- > 0;
     });
     $productsIterator->next()->shouldBeCalled();
     $productsIterator->current()->will(new ReturnPromise([$product]));
     $product->getId()->willReturn(42);
     $tshirt->getId()->willReturn(12);
     $tshirt->getProducts()->willReturn($products);
     $this->normalize($tshirt, 'internal_api', $options)->shouldReturn(['code' => 'my_variant', 'axis' => ['color', 'size'], 'type' => 'variant', 'values' => $valuesLocalized, 'products' => [42], 'meta' => ['id' => 12, 'form' => 'pim-variant-group-edit-form', 'structure_version' => 1, 'model_type' => 'variant_group', 'created' => 'normalized_oldest_log', 'updated' => 'normalized_newest_log']]);
 }
 function it_clears_cache(StepExecution $stepExecution, ProductInterface $product1, ProductInterface $product2)
 {
     $items = [$product1, $product2];
     $product1->getId()->willReturn('45');
     $product2->getId()->willReturn(null);
     $this->setStepExecution($stepExecution);
     $this->write($items);
 }
Ejemplo n.º 5
0
 /**
  * @param ProductInterface $product
  */
 protected function incrementCount(ProductInterface $product)
 {
     if ($product->getId()) {
         $this->stepExecution->incrementSummaryInfo('process');
     } else {
         $this->stepExecution->incrementSummaryInfo('create');
     }
 }
 function it_clears_cache($stepExecution, ProductInterface $product1, ProductInterface $product2, JobParameters $jobParameters)
 {
     $stepExecution->getJobParameters()->willReturn($jobParameters);
     $jobParameters->get('realTimeVersioning')->willReturn(true);
     $items = [$product1, $product2];
     $product1->getId()->willReturn('45');
     $product2->getId()->willReturn(null);
     $stepExecution->incrementSummaryInfo('create')->shouldBeCalled();
     $stepExecution->incrementSummaryInfo('process')->shouldBeCalled();
     $this->write($items);
 }
 function it_find_previous_and_next_products($productRepository, SequentialEdit $sequentialEdit, ProductInterface $product, ProductInterface $previous, ProductInterface $next)
 {
     $sequentialEdit->getObjectSet()->willReturn([1, 6, 5, 2]);
     $sequentialEdit->countObjectSet()->willReturn(4);
     $product->getId()->willReturn(5);
     $productRepository->findOneByWithValues(6)->willReturn($previous);
     $productRepository->findOneByWithValues(2)->willReturn($next);
     $sequentialEdit->setCurrent($product)->shouldBeCalled();
     $sequentialEdit->setPrevious($previous)->shouldBeCalled();
     $sequentialEdit->setNext($next)->shouldBeCalled();
     $this->findWrap($sequentialEdit, $product);
 }
 function it_builds_pending_versions_for_a_given_entity(ProductInterface $product, $builder, $versionRepository)
 {
     $product->getId()->willReturn(1);
     $pending1 = new Version('Product', 1, 'julia');
     $pending1->setChangeset(['foo' => 'bar']);
     $pending2 = new Version('Product', 1, 'julia');
     $pending2->setChangeset(['foo' => 'fubar']);
     $versionRepository->findBy(Argument::cetera())->willReturn([$pending1, $pending2]);
     $builder->buildPendingVersion($pending1, null)->willReturn($pending1)->shouldBeCalled();
     $builder->buildPendingVersion($pending2, $pending1)->willReturn($pending2)->shouldBeCalled();
     $versions = $this->buildPendingVersions($product);
     $versions->shouldHaveCount(2);
 }
 function it_creates_pending_version($versionFactory, ProductInterface $product, Version $pending)
 {
     $product->getId()->willReturn(1);
     $versionFactory->create(Argument::Any(), 1, 'baz', null)->willReturn($pending);
     $pending->getChangeset()->willReturn($pending);
     $pending->setChangeset([])->willReturn($pending);
     $pending->getAuthor()->willReturn('baz');
     $pending->isPending()->willReturn(true);
     $version = $this->createPendingVersion($product, 'baz', []);
     $version->shouldBeAnInstanceOf('Pim\\Bundle\\VersioningBundle\\Model\\Version');
     $version->getAuthor()->shouldReturn('baz');
     $version->isPending()->shouldReturn(true);
 }
 function it_applies_a_filter_on_product_when_its_in_an_expected_association(FilterDatasourceAdapterInterface $datasource, $utility, QueryBuilder $qb, $extractor, $assocRepository, AssociationTypeInterface $assocType, AbstractAssociation $association, ProductInterface $productOwner, ProductInterface $productAssociatedOne, ProductInterface $productAssociatedTwo, $productRepository)
 {
     $extractor->getDatagridParameter('_parameters', [])->willReturn([]);
     $extractor->getDatagridParameter('associationType')->willReturn(1);
     $assocRepository->findOneBy(Argument::any())->willReturn($assocType);
     $extractor->getDatagridParameter('product')->willReturn(11);
     $productRepository->findOneByWithValues(11)->willReturn($productOwner);
     $productOwner->getAssociationForType($assocType)->willReturn($association);
     $association->getProducts()->willReturn([$productAssociatedOne, $productAssociatedTwo]);
     $productAssociatedOne->getId()->willReturn(12);
     $productAssociatedTwo->getId()->willReturn(13);
     $utility->applyFilter($datasource, 'id', 'IN', [12, 13])->shouldBeCalled();
     $this->apply($datasource, ['type' => null, 'value' => 1]);
 }
 function it_massively_insert_and_update_objects($bulkSaver, $bulkDetacher, $stepExecution, ProductInterface $product1, ProductInterface $product2, AssociationInterface $association2)
 {
     $bulkSaver->saveAll([$product1, $product2]);
     $bulkDetacher->detachAll([$product1, $product2]);
     $product1->getId()->willReturn(null);
     $association1 = new Association();
     $product1->getAssociations()->willReturn(new ArrayCollection([$association1]));
     $stepExecution->incrementSummaryInfo('process')->shouldBeCalled();
     $product2->getId()->willReturn(42);
     $association2->getId()->willReturn(1);
     $product2->getAssociations()->willReturn(new ArrayCollection([$association2]));
     $stepExecution->incrementSummaryInfo('process')->shouldBeCalled();
     $this->write([$product1, $product2]);
 }
Ejemplo n.º 12
0
 /**
  * Returns the required attribute codes for a product
  *
  * @param ProductInterface $product
  *
  * @return array
  */
 public function getRequiredAttributeCodes(ProductInterface $product)
 {
     $codes = [];
     if ($product->getFamily()) {
         $codes = $this->getFamilyAttributeCodes($product->getFamily());
     }
     foreach ($product->getGroups() as $group) {
         $codes = array_merge($codes, $this->getGroupAttributeCodes($group));
     }
     if ($product->getId()) {
         foreach ($product->getValues() as $value) {
             $codes[] = $value->getAttribute()->getCode();
         }
     }
     return array_unique($codes);
 }
 function it_normalizes_an_association_with_products_and_groups($mongoFactory, Association $assoc, AssociationTypeInterface $assocType, \MongoId $mongoId, \MongoDBRef $ownerRef, ProductInterface $product1, \MongoDBRef $product1Ref, ProductInterface $product2, \MongoDBRef $product2Ref, GroupInterface $group1, GroupInterface $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]]);
 }
 function it_does_not_set_values_when_attribute_is_not_editable($validator, $productUpdater, $productDetacher, $productRepository, ProductInterface $product, ProductValueInterface $productValue, StepExecution $stepExecution, JobExecution $jobExecution, JobParameters $jobParameters)
 {
     $this->setStepExecution($stepExecution);
     $product->getIdentifier()->shouldBeCalled()->willReturn($productValue);
     $product->getId()->willReturn(10);
     $productValue->getData()->shouldBeCalled();
     $stepExecution->getJobParameters()->willReturn($jobParameters);
     $jobParameters->get('filters')->willReturn([]);
     $jobParameters->get('actions')->willReturn(['normalized_values' => json_encode(['categories' => [['scope' => null, 'locale' => null, 'data' => ['office', 'bedroom']]]]), 'ui_locale' => 'en_US', 'attribute_locale' => 'en_US', 'attribute_channel' => null]);
     $stepExecution->getJobExecution()->willReturn($jobExecution);
     $stepExecution->incrementSummaryInfo('skipped_products')->shouldBeCalled();
     $stepExecution->addWarning('pim_enrich.mass_edit_action.edit-common-attributes.message.no_valid_attribute', [], Argument::any())->shouldBeCalled();
     $productDetacher->detach($product)->shouldBeCalled();
     $violations = new ConstraintViolationList([]);
     $validator->validate($product)->willReturn($violations);
     $productRepository->hasAttributeInFamily(10, 'categories')->shouldBeCalled()->willReturn(true);
     $productRepository->hasAttributeInVariantGroup(10, 'categories')->shouldBeCalled()->willReturn(true);
     $productUpdater->update($product, Argument::any())->shouldNotBeCalled();
     $this->process($product)->shouldReturn(null);
 }
 /**
  * @param array                 $result
  * @param string                $associationTypeId
  * @param ProductInterface|null $product
  *
  * @return array
  */
 public function transform(array $result, $associationTypeId, ProductInterface $product = null)
 {
     if ($product) {
         $associationTypeId = (int) $associationTypeId;
         $result['is_associated'] = false;
         $currentAssociation = $product->getAssociations()->filter(function ($association) use($associationTypeId) {
             return $association->getAssociationType()->getId() === $associationTypeId;
         })->first();
         if ($currentAssociation) {
             $associatedIds = $currentAssociation->getProducts()->map(function ($product) {
                 return $product->getId();
             })->toArray();
             if (in_array($result['id'], $associatedIds)) {
                 $result['is_associated'] = true;
             }
         }
         $result['is_checked'] = $result['is_associated'];
     }
     return $result;
 }
Ejemplo n.º 16
0
 function it_inserts_or_updates_several_products($versionSaver, $normalizer, $collection, ProductInterface $productA, ProductInterface $productB, ProductInterface $productC, ProductInterface $productD)
 {
     $products = [$productA, $productB, $productC, $productD];
     $productA->getId()->willReturn('id_a');
     $productB->getId()->willReturn('id_b');
     $productC->getId()->willReturn(null);
     $productD->getId()->willReturn(null);
     $productA->setId(Argument::any())->shouldNotBeCalled();
     $productB->setId(Argument::any())->shouldNotBeCalled();
     $productC->setId(Argument::any())->shouldBeCalled();
     $productD->setId(Argument::any())->shouldBeCalled();
     $normalizer->normalize($productA, Argument::cetera())->willReturn(['_id' => 'id_a', 'key_a' => 'data_a']);
     $normalizer->normalize($productB, Argument::cetera())->willReturn(['_id' => 'id_b', 'key_b' => 'data_b']);
     $normalizer->normalize($productC, Argument::cetera())->willReturn(['_id' => 'id_c', 'key_c' => 'data_c']);
     $normalizer->normalize($productD, Argument::cetera())->willReturn(['_id' => 'id_d', 'key_d' => 'data_d']);
     $collection->batchInsert([['_id' => 'id_c', 'key_c' => 'data_c'], ['_id' => 'id_d', 'key_d' => 'data_d']])->shouldBeCalled();
     $collection->update(['_id' => 'id_a'], ['_id' => 'id_a', 'key_a' => 'data_a'])->shouldBeCalled();
     $collection->update(['_id' => 'id_b'], ['_id' => 'id_b', 'key_b' => 'data_b'])->shouldBeCalled();
     $versionSaver->saveAll(Argument::any())->shouldBeCalled();
     $this->saveAll($products);
 }
 function it_normalizes_an_existing_product_without_family_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)
 {
     $mongoFactory->createMongoId('product1')->willReturn($mongoId);
     $mongoFactory->createMongoDate()->willReturn($mongoDate);
     $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(null);
     $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, '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' => []]);
 }
 /**
  * Constructor
  *
  * @param ProductInterface $product
  */
 public function __construct(ProductInterface $product)
 {
     parent::__construct(sprintf('Product %s has no identifier attribute', $product->getId()));
 }
 /**
  * Schedule recalculation of completenesses for a product
  *
  * @param ProductInterface $product
  */
 public function schedule(ProductInterface $product)
 {
     if ($product->getId()) {
         $this->generator->schedule($product);
     }
 }
 /**
  * {@inheritdoc}
  *
  * TODO: find a way to do it efficiently
  */
 public function findByProductAndOwnerIds(ProductInterface $product, array $ownerIds)
 {
     $ownerIds = array_map(function ($id) {
         return new \MongoId($id);
     }, $ownerIds);
     // retrieve products whom associations are concerned
     $qb = $this->createQueryBuilder('p');
     $qb->select('associations')->field('_id')->in($ownerIds)->field('associations.products.$id')->equals(new \MongoId($product->getId()));
     $products = $qb->getQuery()->execute();
     $associations = [];
     // filter associations
     foreach ($products as $dummyProduct) {
         foreach ($dummyProduct->getAssociations() as $association) {
             if ($association->hasProduct($product)) {
                 $associations[] = $association;
             }
         }
     }
     return $associations;
 }
 function it_skips_a_product_when_there_is_nothing_to_update_with_localized_value($arrayConverter, $productRepository, $productBuilder, $productUpdater, $productFilter, $localizedConverter, ProductInterface $product, ConstraintViolationListInterface $violationList)
 {
     $productRepository->getIdentifierProperties()->willReturn(['sku']);
     $productRepository->findOneByIdentifier('tshirt')->willReturn(false);
     $this->setDecimalSeparator(',');
     $product->getId()->willReturn(42);
     $productBuilder->createProduct('tshirt', null)->willReturn($product);
     $originalData = ['sku' => 'tshirt', 'number' => '10.45'];
     $postConvertedData = $convertedData = ['sku' => [['locale' => null, 'scope' => null, 'data' => 'tshirt']], 'number' => [['locale' => null, 'scope' => null, 'data' => '10,45']]];
     $converterOptions = ['mapping' => ['family' => 'family', 'categories' => 'categories', 'groups' => 'groups'], 'default_values' => ['enabled' => true], 'with_associations' => false];
     $arrayConverter->convert($originalData, $converterOptions)->willReturn($convertedData);
     $postConvertedData['number'][0]['data'] = '10.45';
     $localizedConverter->convertLocalizedToDefaultValues($convertedData, ['decimal_separator' => ',', 'date_format' => 'yyyy-MM-dd'])->willReturn($postConvertedData);
     $localizedConverter->getViolations()->willReturn($violationList);
     $filteredData = ['number' => [['locale' => null, 'scope' => null, 'data' => '10.45']]];
     $productFilter->filter($product, $filteredData)->willReturn([]);
     $productUpdater->update($product, $filteredData)->shouldNotBeCalled();
     $this->process($originalData)->shouldReturn(null);
 }
 /**
  * @param ProductInterface         $product
  * @param AssociationTypeInterface $type
  *
  * @return array
  */
 protected function getAssociatedProductIds(ProductInterface $product, AssociationTypeInterface $type)
 {
     $productIds = [];
     $association = $product->getAssociationForType($type);
     if ($association) {
         foreach ($association->getProducts() as $product) {
             $productIds[] = $product->getId();
         }
     }
     return $productIds ?: [0];
 }
 /**
  * spl_object_hash for new product and id when product exists
  *
  * @param ProductInterface $product
  *
  * @return string
  */
 protected function getProductIdentifier(ProductInterface $product)
 {
     $identifier = $product->getId() ? $product->getId() : spl_object_hash($product);
     return $identifier;
 }
 /**
  * Fill the array with products id based on their variant axis combination as key
  *
  * @param ProductInterface $product
  * @param array            $productAttributeAxis
  * @param string           $keyCombination
  *
  * @return array
  */
 protected function fillDuplicateCombinationsArray(ProductInterface $product, array $productAttributeAxis, $keyCombination)
 {
     if (array_key_exists($keyCombination, $productAttributeAxis)) {
         $productAttributeAxis[$keyCombination][] = $product->getId();
     } else {
         $productAttributeAxis[$keyCombination] = [$product->getId()];
     }
     return $productAttributeAxis;
 }
 /**
  * {@inheritdoc}
  */
 public function findByProductAndOwnerIds(ProductInterface $product, array $ownerIds)
 {
     $qb = $this->createQueryBuilder('pa');
     $qb->join('pa.products', 'pap', Join::WITH, 'pap.id = :productId')->where($qb->expr()->in('pa.owner', $ownerIds))->setParameter(':productId', $product->getId());
     return $qb->getQuery()->getResult();
 }
 /**
  * Find wrapped products from a product
  *
  * @param SequentialEdit   $sequentialEdit
  * @param ProductInterface $product
  */
 public function findWrap(SequentialEdit $sequentialEdit, ProductInterface $product)
 {
     $objectSet = $sequentialEdit->getObjectSet();
     $currentKey = array_search($product->getId(), $objectSet);
     $previous = $this->findPrevious($sequentialEdit, $currentKey);
     $next = $this->findNext($sequentialEdit, $currentKey);
     $sequentialEdit->setCurrent($product);
     $sequentialEdit->setPrevious($previous);
     $sequentialEdit->setNext($next);
 }
 /**
  * Get matching products
  *
  * @param GroupInterface   $variantGroup the variant group
  * @param ProductInterface $entity       the product
  * @param array            $criteria     query criterias
  *
  * @return ProductInterface[]
  */
 protected function getMatchingProducts(GroupInterface $variantGroup, ProductInterface $entity = null, array $criteria = [])
 {
     if (!$variantGroup->getId()) {
         return [];
     }
     $matchingProducts = $this->repository->findAllForVariantGroup($variantGroup, $criteria);
     if ($entity) {
         $matchingProducts = array_filter($matchingProducts, function ($product) use($entity) {
             return $product->getId() !== $entity->getId();
         });
     }
     return $matchingProducts;
 }
 function it_adds_a_violation_when_validating_product_in_groups_with_non_unique_combination_of_axis_attributes($context, $productRepository, GroupInterface $tShirtVariantGroup, ProductInterface $redTShirtProduct, AttributeInterface $sizeAttribute, AttributeInterface $colorAttribute, ProductValueInterface $sizeProductValue, ProductValueInterface $colorProductValue, ProductInterface $redTShirtProduct2, UniqueVariantAxis $uniqueVariantAxisConstraint, ConstraintViolationBuilderInterface $violation)
 {
     $redTShirtProduct->getVariantGroup()->willReturn($tShirtVariantGroup);
     $tShirtVariantGroup->getId()->willReturn(1);
     $tShirtVariantGroup->getLabel()->willReturn('TShirts');
     $tShirtVariantGroup->getAxisAttributes()->willReturn([$sizeAttribute, $colorAttribute]);
     $sizeAttribute->getCode()->willReturn('size');
     $sizeAttribute->isBackendTypeReferenceData()->willReturn(true);
     $sizeAttribute->getReferenceDataName()->willReturn('ref_size');
     $colorAttribute->getCode()->willReturn('color');
     $colorAttribute->isBackendTypeReferenceData()->willReturn(true);
     $colorAttribute->getReferenceDataName()->willReturn('ref_color');
     $redTShirtProduct->getValue('size')->willReturn($sizeProductValue);
     $redTShirtProduct->getValue('color')->willReturn($colorProductValue);
     $redTShirtProduct->getId()->willReturn(1);
     $sizeProductValue->getData()->willReturn('XL');
     $sizeProductValue->getOption()->willReturn(null);
     $colorProductValue->getData()->willReturn('Red');
     $colorProductValue->getOption()->willReturn(null);
     $criteria = [['attribute' => $sizeAttribute, 'referenceData' => ['name' => 'ref_size', 'data' => 'XL']], ['attribute' => $colorAttribute, 'referenceData' => ['name' => 'ref_color', 'data' => 'Red']]];
     $productRepository->findAllForVariantGroup($tShirtVariantGroup, $criteria)->shouldBeCalled()->willReturn([$redTShirtProduct2]);
     $context->buildViolation('Group "%variant group%" already contains another product with values "%values%"', ['%variant group%' => 'TShirts', '%values%' => 'size: XL, color: Red'])->shouldBeCalled()->willReturn($violation);
     $this->validate($redTShirtProduct, $uniqueVariantAxisConstraint);
 }
Ejemplo n.º 29
0
 /**
  * Search the number of indexed products
  *
  * @param ProductInterface $product
  *
  * @return int
  */
 public function countEditedProducts(ProductInterface $product)
 {
     return array_search($product->getId(), $this->objectSet) + 1;
 }
 /**
  * {@inheritdoc}
  */
 public function generateMissingForProduct(ProductInterface $product)
 {
     $this->generate(['productId' => $product->getId()]);
 }