本文整理汇总了PHP中Pim\Bundle\CatalogBundle\Model\ProductValueInterface::getAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductValueInterface::getAttribute方法的具体用法?PHP ProductValueInterface::getAttribute怎么用?PHP ProductValueInterface::getAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pim\Bundle\CatalogBundle\Model\ProductValueInterface
的用法示例。
在下文中一共展示了ProductValueInterface::getAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepareValueFormData
/**
* {@inheritdoc}
*/
public function prepareValueFormData(ProductValueInterface $value)
{
if (!is_null($value->getData())) {
return $value->getData();
}
$data = $this->metricFactory->createMetric($value->getAttribute()->getMetricFamily());
$data->setData($value->getAttribute()->getDefaultValue());
return $data;
}
示例2: validateComplexValue
/**
* Validate a more complex value that doesn't store the data itself
*
* @param ProductValueInterface $value
* @param Constraint $constraint
*
* @return null
*/
protected function validateComplexValue(ProductValueInterface $value, Constraint $constraint)
{
if ($value->getAttribute()) {
$backendType = $value->getAttribute()->getBackendType();
if ($backendType === 'prices') {
$this->validatePrices($value, $constraint);
} elseif ($backendType === 'media') {
$this->validateMedia($value, $constraint);
} elseif ($backendType === 'metric') {
$this->validateMetric($value, $constraint);
}
}
}
示例3: prepareValueFormData
/**
* {@inheritdoc}
*/
public function prepareValueFormData(ProductValueInterface $value)
{
if ($value->getData() && $value->getData()->isEmpty()) {
return $value->getAttribute()->getDefaultValue();
}
$iterator = $value->getData()->getIterator();
if (true === $value->getAttribute()->getProperty('autoOptionSorting')) {
$iterator->uasort('strcasecmp');
} else {
$iterator->uasort(function ($first, $second) {
return $first->getSortOrder() < $second->getSortOrder() ? -1 : 1;
});
}
return new ArrayCollection(iterator_to_array($iterator));
}
示例4: prepareValueFormOptions
/**
* {@inheritdoc}
*/
public function prepareValueFormOptions(ProductValueInterface $value)
{
$referenceDataConf = $this->referenceDataRegistry->get($value->getAttribute()->getReferenceDataName());
$options = parent::prepareValueFormOptions($value);
$options['class'] = $referenceDataConf->getClass();
return $options;
}
示例5:
function it_converts_metric_values_given_the_configured_base_unit_in_the_channel($converter, ProductValueInterface $weightValue, ProductValueInterface $surfaceValue, ProductValueInterface $nameValue, AttributeInterface $weight, AttributeInterface $surface, AttributeInterface $name, MetricInterface $weightMetric, MetricInterface $surfaceMetric, ProductInterface $product, ChannelInterface $channel)
{
$weightValue->getAttribute()->willReturn($weight);
$weightValue->getData()->willReturn($weightMetric);
$weight->getCode()->willReturn('weight');
$weightMetric->getFamily()->willReturn('Weight');
$weightMetric->getUnit()->willReturn('KILOGRAM');
$weightMetric->getData()->willReturn(1);
$surfaceValue->getAttribute()->willReturn($surface);
$surfaceValue->getData()->willReturn($surfaceMetric);
$surface->getCode()->willReturn('surface');
$surfaceMetric->getFamily()->willReturn('Surface');
$surfaceMetric->getUnit()->willReturn('METER_SQUARE');
$surfaceMetric->getData()->willReturn(10);
$nameValue->getAttribute()->willReturn($name);
$nameValue->getData()->willReturn('foobar');
$product->getValues()->willReturn(array($weightValue, $surfaceValue, $nameValue));
$channel->getConversionUnits()->willReturn(array('weight' => 'GRAM'));
$converter->setFamily('Weight')->shouldBeCalled();
$converter->convert('KILOGRAM', 'GRAM', 1)->willReturn(0.001);
$converter->setFamily('Surface')->shouldNotBeCalled();
$weightMetric->setData(0.001)->shouldBeCalled();
$weightMetric->setUnit('GRAM')->shouldBeCalled();
$this->convert($product, $channel);
}
示例6: let
function let(AttributeConstraintGuesser $guesser, ProductValueInterface $value, AttributeInterface $color, AttributeOptionInterface $red)
{
$value->getAttribute()->willReturn($color);
$value->getData()->willReturn(new ArrayCollection([$red]));
$color->getBackendType()->willReturn(AbstractAttributeType::BACKEND_TYPE_OPTIONS);
$this->beConstructedWith(AbstractAttributeType::BACKEND_TYPE_OPTIONS, 'pim_ajax_entity', $guesser);
}
示例7: prepareValueFormAlias
/**
* {@inheritdoc}
*/
public function prepareValueFormAlias(ProductValueInterface $value)
{
if ($value->getAttribute()->isWysiwygEnabled()) {
return 'pim_wysiwyg';
}
return parent::prepareValueFormAlias($value);
}
示例8:
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])->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);
}
示例9:
function it_adds_multiple_product_values_children_in_the_same_group(ProductValueInterface $valueOne, AttributeInterface $attributeOne, ProductValueInterface $valueTwo, AttributeInterface $attributeTwo, AttributeGroup $group, FormView $valueFormView, $viewUpdaterRegistry)
{
$valueOne->getAttribute()->willReturn($attributeOne);
$valueOne->isRemovable()->willReturn(true);
$valueOne->getLocale()->willReturn(null);
$valueOne->getEntity()->willReturn(null);
$attributeOne->getGroup()->willReturn($group);
$attributeOne->getId()->willReturn(42);
$attributeOne->getCode()->willReturn('name');
$attributeOne->getLabel()->willReturn('Name');
$attributeOne->getSortOrder()->willReturn(10);
$attributeOne->getAttributeType()->willReturn('pim_catalog_text');
$attributeOne->isLocalizable()->willReturn(false);
$attributeOne->isScopable()->willReturn(false);
$valueTwo->getAttribute()->willReturn($attributeTwo);
$valueTwo->isRemovable()->willReturn(true);
$valueTwo->getLocale()->willReturn(null);
$valueTwo->getEntity()->willReturn(null);
$attributeTwo->getGroup()->willReturn($group);
$attributeTwo->getId()->willReturn(47);
$attributeTwo->getCode()->willReturn('description');
$attributeTwo->getLabel()->willReturn('Description');
$attributeTwo->getSortOrder()->willReturn(15);
$attributeTwo->getAttributeType()->willReturn('pim_catalog_text');
$attributeTwo->isLocalizable()->willReturn(false);
$attributeTwo->isScopable()->willReturn(false);
$group->getId()->willReturn(1);
$group->getCode()->willReturn('general');
$group->getLabel()->willReturn('General');
$this->addChildren($valueOne, $valueFormView);
$this->addChildren($valueTwo, $valueFormView);
$viewUpdaterRegistry->getUpdaters()->willReturn([]);
$resultView = [1 => ['label' => 'General', 'attributes' => ['name' => ['id' => 42, 'isRemovable' => true, 'code' => 'name', 'label' => 'Name', 'sortOrder' => 10, 'allowValueCreation' => false, 'locale' => null, 'value' => $valueFormView], 'description' => ['id' => 47, 'isRemovable' => true, 'code' => 'description', 'label' => 'Description', 'sortOrder' => 15, 'allowValueCreation' => false, 'locale' => null, 'value' => $valueFormView]]]];
$this->getView()->shouldReturn($resultView);
}
示例10:
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);
}
示例11: it_suports_media_attribute
public function it_suports_media_attribute(ProductValueInterface $productValue, AttributeInterface $attribute)
{
$productValue->getAttribute()->willReturn($attribute);
$attribute->getBackendType()->willReturn('media');
$this->supportsValue($productValue)->shouldReturn(true);
$attribute->getBackendType()->willReturn('other');
$this->supportsValue($productValue)->shouldReturn(false);
}
示例12: getUniqueValueCode
/**
* @param ProductValueInterface $productValue
*
* @return string
*/
protected function getUniqueValueCode(ProductValueInterface $productValue)
{
$attributeCode = $productValue->getAttribute()->getCode();
$uniqueValueCode = $attributeCode;
$uniqueValueCode .= null !== $productValue->getLocale() ? $productValue->getLocale() : '';
$uniqueValueCode .= null !== $productValue->getScope() ? $productValue->getScope() : '';
return $uniqueValueCode;
}
示例13:
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);
}
示例14: it_suports_metric_attribute
public function it_suports_metric_attribute(ProductValueInterface $productValue, AttributeInterface $attribute)
{
$productValue->getAttribute()->willReturn($attribute);
$attribute->getAttributeType()->willReturn('pim_catalog_metric');
$this->supportsValue($productValue)->shouldReturn(true);
$attribute->getAttributeType()->willReturn('other');
$this->supportsValue($productValue)->shouldReturn(false);
}
示例15: it_succesfully_checks_complete_attribute
public function it_succesfully_checks_complete_attribute(ProductValueInterface $value, ChannelInterface $channel, LocaleInterface $locale, ProductValueCompleteCheckerInterface $completenessChecker, AttributeInterface $attribute)
{
$value->getAttribute()->willReturn($attribute);
$value->getData()->willReturn('foo');
$this->addProductValueChecker($completenessChecker);
$completenessChecker->supportsValue($value)->willReturn(true);
$completenessChecker->isComplete($value, $channel, $locale)->willReturn(true);
$this->isComplete($value, $channel, $locale)->shouldReturn(true);
}