本文整理汇总了PHP中Pim\Component\Catalog\Model\ProductInterface类的典型用法代码示例。如果您正苦于以下问题:PHP ProductInterface类的具体用法?PHP ProductInterface怎么用?PHP ProductInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProductInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
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]);
}
示例2:
function it_allows_setting_attribute_data_option_to_null(ProductInterface $product, AttributeInterface $attribute, ProductValueInterface $value)
{
$attribute->getCode()->willReturn('choice');
$product->getValue('choice', 'fr_FR', 'mobile')->shouldBeCalled()->willReturn($value);
$value->setOption(null)->shouldBeCalled();
$this->setAttributeData($product, $attribute, null, ['locale' => 'fr_FR', 'scope' => 'mobile']);
}
示例3:
function it_provide_product_completeness_if_family_is_not_defined(ProductInterface $product, ChannelInterface $mobile, LocaleInterface $en)
{
$product->getFamily()->willReturn(null);
$en->getCode()->willReturn('en_US');
$mobile->getCode()->willReturn('mobile');
$this->getProductCompleteness($product, [$mobile], [$en], 'en_US')->shouldReturn([['channels' => [['completeness' => null, 'missing' => []]], 'stats' => ['total' => 0, 'complete' => 0], 'locale' => '']]);
}
示例4: foreach
function it_copies_simple_select_value_to_a_product_value($builder, $attrValidatorHelper, AttributeInterface $fromAttribute, AttributeInterface $toAttribute, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, ProductInterface $product4, ProductValueInterface $fromProductValue, ProductValueInterface $toProductValue, AttributeOptionInterface $attributeOption)
{
$fromLocale = 'fr_FR';
$toLocale = 'fr_FR';
$toScope = 'mobile';
$fromScope = 'mobile';
$fromAttribute->getCode()->willReturn('fromAttributeCode');
$toAttribute->getCode()->willReturn('toAttributeCode');
$attrValidatorHelper->validateLocale(Argument::cetera())->shouldBeCalled();
$attrValidatorHelper->validateScope(Argument::cetera())->shouldBeCalled();
$fromProductValue->getData()->willReturn($attributeOption);
$toProductValue->setOption($attributeOption)->shouldBeCalledTimes(3);
$product1->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn($fromProductValue);
$product1->getValue('toAttributeCode', $toLocale, $toScope)->willReturn($toProductValue);
$product2->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn(null);
$product2->getValue('toAttributeCode', $toLocale, $toScope)->willReturn($toProductValue);
$product3->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn($fromProductValue);
$product3->getValue('toAttributeCode', $toLocale, $toScope)->willReturn(null);
$product4->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn($fromProductValue);
$product4->getValue('toAttributeCode', $toLocale, $toScope)->willReturn($toProductValue);
$builder->addProductValue($product3, $toAttribute, $toLocale, $toScope)->shouldBeCalledTimes(1)->willReturn($toProductValue);
$products = [$product1, $product2, $product3, $product4];
foreach ($products as $product) {
$this->copyAttributeData($product, $product, $fromAttribute, $toAttribute, ['from_locale' => $fromLocale, 'to_locale' => $toLocale, 'from_scope' => $fromScope, 'to_scope' => $toScope]);
}
}
示例5: use
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']]);
}
示例6: setData
/**
* Set data into product value
*
* @param ProductInterface $product
* @param AttributeInterface $attribute
* @param mixed $data
* @param string $locale
* @param string $scope
*/
protected function setData(ProductInterface $product, AttributeInterface $attribute, $data, $locale, $scope)
{
$value = $product->getValue($attribute->getCode(), $locale, $scope);
if (null === $value) {
$value = $this->productBuilder->addProductValue($product, $attribute, $locale, $scope);
}
$value->setData($data);
}
示例7: incrementCount
/**
* @param ProductInterface $product
*/
protected function incrementCount(ProductInterface $product)
{
if ($product->getId()) {
$this->stepExecution->incrementSummaryInfo('process');
} else {
$this->stepExecution->incrementSummaryInfo('create');
}
}
示例8:
function it_applies_on_related_products($saver, RemoveEvent $event, CategoryInterface $object, ProductInterface $product)
{
$saver->saveAll([$product])->shouldBeCalled();
$event->getSubject()->willReturn($object);
$object->getProducts()->willReturn([$product]);
$product->removeCategory($object)->shouldBeCalled();
$this->postRemove($event)->shouldReturn(null);
}
示例9: setMedia
/**
* Set media in the product value
*
* @param ProductInterface $product
* @param AttributeInterface $attribute
* @param FileInfoInterface|null $fileInfo
* @param string|null $locale
* @param string|null $scope
*/
protected function setMedia(ProductInterface $product, AttributeInterface $attribute, FileInfoInterface $fileInfo = null, $locale = null, $scope = null)
{
$value = $product->getValue($attribute->getCode(), $locale, $scope);
if (null === $value) {
$value = $this->productBuilder->addProductValue($product, $attribute, $locale, $scope);
}
$value->setMedia($fileInfo);
}
示例10: shouldBeSetInProduct
/**
* As boolean attribute does not support "null" value (only true/false),
* there are some problems to make out what should really be added to the product (specially with optional attributes)
* What we add in product:
* | old value | new value | attribute is in family | should be added in product |
* | null | false | yes | no |
* | null | false | no | yes |
*
* This method should be removed when boolean attribute will be rework to support 3 states: true/false/null
*
* @deprecated will be removed in 1.7
*
* @param ProductInterface $product product to update
* @param AttributeInterface $attribute attribute
* @param mixed $data new value
*
* @return bool
*/
private function shouldBeSetInProduct(ProductInterface $product, AttributeInterface $attribute, $data)
{
$family = $product->getFamily();
if (null !== $family && in_array($attribute->getCode(), $product->getFamily()->getAttributeCodes()) && false === $data) {
return false;
}
return true;
}
示例11:
function it_fails_if_one_of_the_associated_group_does_not_exist($productBuilder, $groupRepository, ProductInterface $product, AssociationInterface $xsellAssociation)
{
$product->getAssociations()->willReturn([$xsellAssociation]);
$productBuilder->addMissingAssociations($product)->shouldBeCalled();
$product->getAssociationForTypeCode('xsell')->willReturn($xsellAssociation);
$groupRepository->findOneByIdentifier('not existing group')->willReturn(null);
$this->shouldThrow(InvalidArgumentException::expected('associations', 'existing group code', 'adder', 'association', 'not existing group'))->during('addFieldData', [$product, 'associations', ['xsell' => ['groups' => ['not existing group'], 'products' => []]]]);
}
示例12:
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);
}
示例13: setOption
/**
* Set option into the product value
*
* @param ProductInterface $product
* @param AttributeInterface $attribute
* @param AttributeOptionInterface|null $option
* @param string|null $locale
* @param string|null $scope
*/
protected function setOption(ProductInterface $product, AttributeInterface $attribute, AttributeOptionInterface $option = null, $locale = null, $scope = null)
{
$value = $product->getValue($attribute->getCode(), $locale, $scope);
if (null === $value) {
$value = $this->productBuilder->addProductValue($product, $attribute, $locale, $scope);
}
$value->setOption($option);
}
示例14:
function it_returns_flat_data_without_media(ChannelInterface $channel, ChannelManager $channelManager, ProductInterface $product, Serializer $serializer)
{
$product->getValues()->willReturn([]);
$this->setDecimalSeparator(',');
$serializer->normalize($product, 'flat', ['scopeCode' => 'foobar', 'localeCodes' => '', 'decimal_separator' => ',', 'date_format' => 'yyyy-MM-dd'])->willReturn(['normalized_product']);
$channelManager->getChannelByCode('foobar')->willReturn($channel);
$this->setChannel('foobar');
$this->process($product)->shouldReturn(['media' => [], 'product' => ['normalized_product']]);
}
示例15: let
function let(ProductRepositoryInterface $productRepository, UniqueValuesSet $uniqueValuesSet, ExecutionContextInterface $context, Form $form, ProductInterface $product, ProductValueInterface $value)
{
$this->beConstructedWith($productRepository, $uniqueValuesSet);
$product->getValue('unique_attribute')->willReturn($value);
$form->getData()->willReturn($product);
$context->getPropertyPath()->willReturn(self::PROPERTY_PATH);
$context->getRoot()->willReturn($form);
$this->initialize($context);
}