本文整理汇总了PHP中Pim\Component\Catalog\Model\ProductValueInterface类的典型用法代码示例。如果您正苦于以下问题:PHP ProductValueInterface类的具体用法?PHP ProductValueInterface怎么用?PHP ProductValueInterface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProductValueInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: let
function let(AttributeConstraintGuesser $guesser, ProductValueInterface $value, AttributeInterface $color, AttributeOptionInterface $red)
{
$value->getAttribute()->willReturn($color);
$value->getData()->willReturn(new ArrayCollection([$red]));
$color->getBackendType()->willReturn(AttributeTypes::BACKEND_TYPE_OPTIONS);
$this->beConstructedWith(AttributeTypes::BACKEND_TYPE_OPTIONS, 'pim_ajax_entity', $guesser);
}
示例2: use
function it_normalizes_the_properties_of_the_product($filter, $serializer, ProductInterface $product, AttributeInterface $attribute, ProductValueInterface $value, FamilyInterface $family, ArrayCollection $values, \ArrayIterator $iterator, ProductValueInterface $identifier)
{
$values->getIterator()->willReturn($iterator);
$family->getCode()->willReturn('my_family');
$product->getFamily()->willReturn($family);
$product->getGroupCodes()->willReturn([]);
$product->getVariantGroup()->willReturn(null);
$product->getCategoryCodes()->willReturn([]);
$product->isEnabled()->willReturn(true);
$value->getAttribute()->willReturn($attribute);
$attribute->getCode()->willReturn('name');
$product->getIdentifier()->willReturn($identifier);
$identifier->getData()->willReturn('my_code');
$product->getValues()->willReturn($values);
$filter->filterCollection($values, 'pim.transform.product_value.structured', Argument::type('array'))->shouldBeCalled()->willReturn($values);
$iterator->rewind()->willReturn(null);
$valueCount = 1;
$iterator->valid()->will(function () use(&$valueCount) {
return $valueCount-- > 0;
});
$iterator->current()->willReturn($value);
$iterator->next()->willReturn(null);
$context = ['filter_types' => ['pim.transform.product_value.structured']];
$serializer->normalize($value, 'standard', $context)->willReturn(['locale' => null, 'scope' => null, 'value' => 'foo']);
$created = new \DateTime('2010-06-23');
$product->getCreated()->willReturn($created);
$serializer->normalize($created, 'standard')->willReturn('2010-06-23T00:00:00+01:00');
$updated = new \DateTime('2010-06-23 23:00:00');
$product->getUpdated()->willReturn($updated);
$serializer->normalize($updated, 'standard')->willReturn('2010-06-23T23:00:00+01:00');
$this->normalize($product, 'standard', $context)->shouldReturn(['identifier' => 'my_code', 'family' => 'my_family', 'groups' => [], 'variant_group' => null, 'categories' => [], 'enabled' => true, 'values' => ['name' => [['locale' => null, 'scope' => null, 'value' => 'foo']]], 'created' => '2010-06-23T00:00:00+01:00', 'updated' => '2010-06-23T23:00:00+01:00']);
}
示例3: prepareValueFormOptions
/**
* {@inheritdoc}
*/
public function prepareValueFormOptions(ProductValueInterface $value)
{
$referenceDataConf = $this->referenceDataRegistry->get($value->getAttribute()->getReferenceDataName());
$options = parent::prepareValueFormOptions($value);
$options['class'] = $referenceDataConf->getClass();
return $options;
}
示例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: prepareValueFormAlias
/**
* {@inheritdoc}
*/
public function prepareValueFormAlias(ProductValueInterface $value)
{
if ($value->getAttribute()->isWysiwygEnabled()) {
return 'pim_wysiwyg';
}
return parent::prepareValueFormAlias($value);
}
示例6: use
function it_allows_to_get_errors_if_the_copy_went_wrong($mediaFetcher, $filesystemProvider, $fileExporterPath, FileInfoInterface $fileInfo, FileInfoInterface $fileInfo2, ArrayCollection $productValuesCollection, \ArrayIterator $valuesIterator, ProductValueInterface $productValue, ProductValueInterface $productValue2, AttributeInterface $attribute, FilesystemInterface $filesystem)
{
$fileInfo->getStorage()->willReturn('storageAlias');
$fileInfo->getKey()->willReturn('a/b/c/d/product.jpg');
$fileInfo->getOriginalFilename()->willReturn('my product.jpg');
$fileInfo2->getStorage()->willReturn('storageAlias');
$fileInfo2->getKey()->willReturn('wrong-path.jpg');
$fileInfo2->getOriginalFilename()->willReturn('my-second-media.jpg');
$productValue->getAttribute()->willReturn($attribute);
$productValue->getMedia()->willReturn($fileInfo);
$productValue->getLocale()->willReturn('en_US');
$productValue->getScope()->willReturn(null);
$productValue2->getAttribute()->willReturn($attribute);
$productValue2->getMedia()->willReturn($fileInfo2);
$productValue2->getLocale()->willReturn('fr_FR');
$productValue2->getScope()->willReturn('ecommerce');
$attribute->getAttributeType()->willReturn('pim_catalog_image');
$attribute->getCode()->willReturn('my_picture');
$productValuesCollection->getIterator()->willReturn($valuesIterator);
$valuesIterator->rewind()->shouldBeCalled();
$valuesCount = 2;
$valuesIterator->valid()->will(function () use(&$valuesCount) {
return $valuesCount-- > 0;
});
$valuesIterator->next()->shouldBeCalled();
$valuesIterator->current()->will(new ReturnPromise([$productValue, $productValue2]));
$filesystemProvider->getFilesystem('storageAlias')->willReturn($filesystem);
$mediaFetcher->fetch($filesystem, 'a/b/c/d/product.jpg', ['filePath' => $this->directory . 'files/the_sku/my_picture/en_US/', 'filename' => 'my product.jpg'])->willThrow(new FileTransferException());
$fileExporterPath->generate(['locale' => 'en_US', 'scope' => null], ['identifier' => 'the_sku', 'code' => 'my_picture'])->willReturn('files/the_sku/my_picture/en_US/');
$mediaFetcher->fetch($filesystem, 'wrong-path.jpg', ['filePath' => $this->directory . 'files/the_sku/my_picture/fr_FR/ecommerce/', 'filename' => 'my-second-media.jpg'])->willThrow(new \LogicException('Something went wrong.'));
$fileExporterPath->generate(['locale' => 'fr_FR', 'scope' => 'ecommerce'], ['identifier' => 'the_sku', 'code' => 'my_picture'])->willReturn('files/the_sku/my_picture/fr_FR/ecommerce/');
$this->fetchAll($productValuesCollection, $this->directory, 'the_sku');
$this->getErrors()->shouldBeEqualTo([['message' => 'The media has not been found or is not currently available', 'media' => ['from' => 'a/b/c/d/product.jpg', 'to' => ['filePath' => $this->directory . 'files/the_sku/my_picture/en_US/', 'filename' => 'my product.jpg'], 'storage' => 'storageAlias']], ['message' => 'The media has not been copied. Something went wrong.', 'media' => ['from' => 'wrong-path.jpg', 'to' => ['filePath' => $this->directory . 'files/the_sku/my_picture/fr_FR/ecommerce/', 'filename' => 'my-second-media.jpg'], 'storage' => 'storageAlias']]]);
}
示例7: ArrayCollection
function it_returns_flat_data_with_media($channelManager, Filesystem $filesystem, ChannelInterface $channel, LocaleInterface $locale, ProductInterface $product, FileInfoInterface $media1, FileInfoInterface $media2, ProductValueInterface $value1, ProductValueInterface $value2, AttributeInterface $attribute, ProductValueInterface $identifierValue, AttributeInterface $identifierAttribute, $serializer, $productBuilder)
{
$localeCodes = ['en_US'];
$channel->getLocales()->willReturn(new ArrayCollection([$locale]));
$channel->getLocaleCodes()->willReturn($localeCodes);
$productBuilder->addMissingProductValues($product, [$channel], [$locale])->shouldBeCalled();
$media1->getKey()->willReturn('key/to/media1.jpg');
$media2->getKey()->willReturn('key/to/media2.jpg');
$value1->getAttribute()->willReturn($attribute);
$value1->getMedia()->willReturn($media1);
$value2->getAttribute()->willReturn($attribute);
$value2->getMedia()->willReturn($media2);
$attribute->getAttributeType()->willReturn('pim_catalog_image');
$product->getValues()->willReturn([$value1, $value2, $identifierValue]);
$identifierValue->getAttribute()->willReturn($identifierAttribute);
$identifierAttribute->getAttributeType()->willReturn('pim_catalog_identifier');
$product->getIdentifier()->willReturn($identifierValue);
$identifierValue->getData()->willReturn('data');
$filesystem->has('key/to/media1.jpg')->willReturn(true);
$filesystem->has('key/to/media2.jpg')->willReturn(true);
$serializer->normalize($media1, 'flat', ['field_name' => 'media', 'prepare_copy' => true, 'value' => $value1])->willReturn(['normalized_media1']);
$serializer->normalize($media2, 'flat', ['field_name' => 'media', 'prepare_copy' => true, 'value' => $value2])->willReturn(['normalized_media2']);
$serializer->normalize($product, 'flat', ['scopeCode' => 'foobar', 'localeCodes' => $localeCodes, 'decimal_separator' => '.', 'date_format' => 'yyyy-MM-dd'])->willReturn(['normalized_product']);
$channelManager->getChannelByCode('foobar')->willReturn($channel);
$this->setChannel('foobar');
$this->process($product)->shouldReturn(['media' => [['normalized_media1'], ['normalized_media2']], 'product' => ['normalized_product']]);
}
示例8: prepareValueFormData
/**
* {@inheritdoc}
*/
public function prepareValueFormData(ProductValueInterface $value)
{
if (!is_null($value->getData())) {
return $value->getData();
}
return $this->metricFactory->createMetric($value->getAttribute()->getMetricFamily());
}
示例9:
function it_adds_missing_product_values_from_family_on_new_product($valuesResolver, FamilyInterface $family, ProductInterface $product, AttributeInterface $sku, AttributeInterface $name, AttributeInterface $desc, ProductValueInterface $skuValue)
{
$sku->getCode()->willReturn('sku');
$sku->getAttributeType()->willReturn('pim_catalog_identifier');
$sku->isLocalizable()->willReturn(false);
$sku->isScopable()->willReturn(false);
$name->getCode()->willReturn('name');
$name->getAttributeType()->willReturn('pim_catalog_text');
$name->isLocalizable()->willReturn(true);
$name->isScopable()->willReturn(false);
$desc->getCode()->willReturn('description');
$desc->getAttributeType()->willReturn('pim_catalog_text');
$desc->isLocalizable()->willReturn(true);
$desc->isScopable()->willReturn(true);
// get expected attributes
$product->getAttributes()->willReturn([$sku]);
$family->getAttributes()->willReturn([$sku, $name, $desc]);
$product->getFamily()->willReturn($family);
// get eligible values
$valuesResolver->resolveEligibleValues(['sku' => $sku, 'name' => $name, 'description' => $desc], null, null)->willReturn([['attribute' => 'sku', 'type' => 'pim_catalog_identifier', 'locale' => null, 'scope' => null], ['attribute' => 'name', 'type' => 'pim_catalog_text', 'locale' => 'fr_FR', 'scope' => null], ['attribute' => 'name', 'type' => 'pim_catalog_text', 'locale' => 'en_US', 'scope' => null], ['attribute' => 'description', 'type' => 'pim_catalog_text', 'locale' => 'en_US', 'scope' => 'ecommerce'], ['attribute' => 'description', 'type' => 'pim_catalog_text', 'locale' => 'fr_FR', 'scope' => 'ecommerce'], ['attribute' => 'description', 'type' => 'pim_catalog_text', 'locale' => 'en_US', 'scope' => 'print'], ['attribute' => 'description', 'type' => 'pim_catalog_text', 'locale' => 'fr_FR', 'scope' => 'print']]);
// get existing values
$skuValue->getAttribute()->willReturn($sku);
$skuValue->getLocale()->willReturn(null);
$skuValue->getScope()->willReturn(null);
$product->getValues()->willReturn([$skuValue]);
// add 6 new values : 4 desc (locales x scopes) + 2 name (locales
$product->addValue(Argument::any())->shouldBeCalledTimes(6);
$this->addMissingProductValues($product);
}
示例10: validate
/**
* Validate currency of a price
*
* @param AttributeInterface|MetricInterface|ProductValueInterface $object
* @param Constraint $constraint
*/
public function validate($object, Constraint $constraint)
{
if ($object instanceof ProductPriceInterface) {
if (!in_array($object->getCurrency(), $this->getCurrencyCodes())) {
$this->context->buildViolation($constraint->unitMessage)->atPath('currency')->addViolation();
}
}
}
示例11:
function it_denormalizes_a_collection_of_reference_data_values($refDataDenormalizer, AttributeInterface $attribute, ReferenceDataInterface $refData1, ReferenceDataInterface $refData2, ProductValueInterface $productValue)
{
$productValue->getAttribute()->willReturn($attribute);
$context = ['value' => $productValue];
$refDataDenormalizer->denormalize('battlecruiser', 'pim_reference_data_multiselect', null, $context)->shouldBeCalled()->willReturn($refData1);
$refDataDenormalizer->denormalize('destroyer', 'pim_reference_data_multiselect', null, $context)->shouldBeCalled()->willReturn($refData2);
$this->denormalize('battlecruiser,destroyer', 'pim_reference_data_multiselect', null, $context)->shouldHaveCount(2);
}
示例12: supportsValue
/**
* {@inheritdoc}
*/
public function supportsValue(ProductValueInterface $productValue)
{
$data = $productValue->getData();
if (null === $data || '' === $data || [] === $data || $data instanceof \Countable && 0 === count($data)) {
return true;
}
return false;
}
示例13:
function it_denormalizes_data_into_reference_data($resolver, AttributeInterface $attribute, ReferenceDataInterface $battlecruiser, ReferenceDataRepository $referenceDataRepo, ProductValueInterface $productValue)
{
$attribute->getReferenceDataName()->willReturn('starship');
$productValue->getAttribute()->willReturn($attribute);
$resolver->resolve('starship')->willReturn($referenceDataRepo);
$referenceDataRepo->findOneBy(['code' => 'battlecruiser'])->willReturn($battlecruiser);
$this->denormalize('battlecruiser', 'pim_reference_data_simpleselect', 'csv', ['value' => $productValue])->shouldReturn($battlecruiser);
}
示例14: markAttributeAsUpdatedByVariant
/**
* Mark attribute as variant
*
* @param FormView $view
* @param ProductValueInterface $value
*/
protected function markAttributeAsUpdatedByVariant(FormView $view, ProductValueInterface $value)
{
$view->vars['from_variant'] = $value->getEntity()->getVariantGroup();
$view->vars['disabled'] = true;
$view->vars['read_only'] = true;
foreach ($view as $child) {
$this->markAttributeAsUpdatedByVariant($child, $value);
}
}
示例15:
function it_returns_a_price_collection_even_if_the_data_is_empty($productBuilder, ProductValueInterface $priceValue, ProductPriceInterface $price, ArrayCollection $priceCollection)
{
$productBuilder->addPriceForCurrency(Argument::cetera())->willReturn($price);
$priceValue->addPrice($price)->shouldBeCalled();
$priceValue->getPrices()->willReturn($priceCollection);
$context = ['value' => $priceValue, 'price_currency' => 'WillNotBeUsed'];
$this->denormalize('', 'className', null, $context)->shouldReturn($priceCollection);
$this->denormalize(null, 'className', null, $context)->shouldReturn($priceCollection);
}