本文整理汇总了PHP中Pim\Component\Catalog\Repository\AttributeRepositoryInterface类的典型用法代码示例。如果您正苦于以下问题:PHP AttributeRepositoryInterface类的具体用法?PHP AttributeRepositoryInterface怎么用?PHP AttributeRepositoryInterface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AttributeRepositoryInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
function it_denormalizes_product_values_from_json($denormalizer, $registry, AttributeRepositoryInterface $attributeRepository, ProductValueInterface $nameValue, ProductValueInterface $colorValue, AttributeInterface $name, AttributeInterface $color)
{
$data = ['name' => [['locale' => null, 'scope' => null, 'value' => 'foo']], 'color' => [['locale' => 'en_US', 'scope' => 'ecommerce', 'value' => 'red']]];
$attributeRepository->findOneByIdentifier('name')->willReturn($name);
$attributeRepository->findOneByIdentifier('color')->willReturn($color);
$registry->getRepository('Attribute')->willReturn($attributeRepository);
$denormalizer->denormalize($data['name'][0], 'ProductValue', 'json', ['attribute' => $name])->shouldBeCalled()->willReturn($nameValue);
$denormalizer->denormalize($data['color'][0], 'ProductValue', 'json', ['attribute' => $color])->shouldBeCalled()->willReturn($colorValue);
$values = $this->denormalize($data, 'ProductValue[]', 'json');
$values->shouldHaveCount(2);
$values[0]->shouldBe($nameValue);
$values[1]->shouldBe($colorValue);
}
示例2: getMediaAttributes
/**
* Get the media attributes
*
* @return string[]
*/
public function getMediaAttributes()
{
if (null === $this->mediaAttributes) {
$this->mediaAttributes = $this->attributeRepository->findMediaAttributeCodes();
}
return $this->mediaAttributes;
}
示例3: resolveAttributeColumns
/**
* @return array
*/
public function resolveAttributeColumns()
{
if (empty($this->attributesFields)) {
// TODO: Put a Cursor to avoid a findAll on attributes (╯°□°)╯︵ ┻━┻
$attributes = $this->attributeRepository->findAll();
$currencyCodes = $this->currencyRepository->getActivatedCurrencyCodes();
$values = $this->valuesResolver->resolveEligibleValues($attributes);
foreach ($values as $value) {
$field = $this->resolveFlatAttributeName($value['attribute'], $value['locale'], $value['scope']);
if (AttributeTypes::PRICE_COLLECTION === $value['type']) {
$this->attributesFields[] = $field;
foreach ($currencyCodes as $currencyCode) {
$currencyField = sprintf('%s-%s', $field, $currencyCode);
$this->attributesFields[] = $currencyField;
}
} elseif (AttributeTypes::METRIC === $value['type']) {
$this->attributesFields[] = $field;
$metricField = sprintf('%s-%s', $field, 'unit');
$this->attributesFields[] = $metricField;
} else {
$this->attributesFields[] = $field;
}
}
}
return $this->attributesFields;
}
示例4: getFilter
/**
* {@inheritdoc}
*/
public function getFilter($code, $operator)
{
$attribute = $this->attributeRepository->findOneBy(['code' => FieldFilterHelper::getCode($code)]);
if (null !== $attribute) {
return $this->getAttributeFilter($attribute, $operator);
}
return $this->getFieldFilter($code, $operator);
}
示例5: findCommonAttributes
/**
* Find common attributes
* Common attributes are:
* - not unique (and not identifier)
* - without value AND link to family
* - with value
*
* @param ProductInterface[] $products
*
* @return AttributeInterface[]
*/
public function findCommonAttributes(array $products)
{
$productIds = [];
foreach ($products as $product) {
$productIds[] = $product->getId();
}
$attributeIds = $this->massActionRepository->findCommonAttributeIds($productIds);
return $this->attributeRepository->findWithGroups(array_unique($attributeIds), ['conditions' => ['unique' => 0]]);
}
示例6: getAttribute
/**
* Load the attribute for this filter
* Required to prepare choice url params and filter configuration
*
* @throws \LogicException
*
* @return AttributeInterface
*/
protected function getAttribute()
{
$fieldName = $this->get(ProductFilterUtility::DATA_NAME_KEY);
$attribute = $this->attributeRepository->findOneByCode($fieldName);
if (!$attribute) {
throw new \LogicException(sprintf('There is no attribute with code %s.', $fieldName));
}
return $attribute;
}
示例7: validate
/**
* Don't allow creating an identifier attribute if one already exists
*
* @param AttributeInterface $attribute
* @param Constraint $constraint
*/
public function validate($attribute, Constraint $constraint)
{
if (AttributeTypes::IDENTIFIER === $attribute->getAttributeType()) {
$identifier = $this->attributeRepository->getIdentifier();
if ($identifier && $identifier->getId() !== $attribute->getId()) {
$this->context->buildViolation($constraint->message)->atPath('attribute_type')->addViolation();
}
}
}
示例8: getAttributes
/**
* Get a list of available attributes
*
* @param string $typeCode
* @return AttributeInterface[]
*/
public function getAttributes($typeCode)
{
$attributeCodes = $this->repository->getAttributeCodesByType($typeCode);
$attributeList = [];
foreach ($attributeCodes as $attributeCode) {
$attributeList[] = $this->repository->findOneByIdentifier($attributeCode);
}
return $attributeList;
}
示例9: getFieldsList
/**
* Get fields for products
*
* @param array $productIds
*
* @return array
*/
public function getFieldsList($productIds)
{
$this->prepareAvailableAttributeIds($productIds);
$attributes = $this->getAttributeIds();
if (empty($attributes)) {
return [];
}
$attributes = $this->attributeRepository->findBy(['id' => $this->getAttributeIds()]);
return $this->prepareFieldsList($attributes);
}
示例10: normalizeAttributes
/**
* Normalize the attributes
*
* @param FamilyInterface $family
*
* @return array
*/
protected function normalizeAttributes(FamilyInterface $family)
{
$attributes = $this->collectionFilter->filterCollection($this->attributeRepository->findAttributesByFamily($family), 'pim.internal_api.attribute.view');
$normalizedAttributes = [];
foreach ($attributes as $attribute) {
$normalizedAttributes[] = $attribute->getCode();
}
sort($normalizedAttributes);
return $normalizedAttributes;
}
示例11: getAvailableAxisChoices
/**
* Get axis as choice list
*
* @deprecated not used anymore except in datagrid configuration, will be removed in 1.5
*
* @return array
*/
public function getAvailableAxisChoices()
{
$attributes = $this->attributeRepository->findAllAxis();
$choices = [];
foreach ($attributes as $attribute) {
$choices[$attribute->getId()] = $attribute->getLabel();
}
asort($choices);
return $choices;
}
示例12: denormalize
/**
* {@inheritdoc}
*/
public function denormalize($data, $class, $format = null, array $context = [])
{
$values = new ArrayCollection();
foreach ($data as $attributeCode => $valuesData) {
$attribute = $this->attributeRepository->findOneByIdentifier($attributeCode);
foreach ($valuesData as $valueData) {
$value = $this->denormalizer->denormalize($valueData, $this->valueClass, 'json', ['attribute' => $attribute] + $context);
$values->add($value);
}
}
return $values;
}
示例13: createFamily
/**
* @return FamilyInterface
*/
public function createFamily()
{
$family = new $this->familyClass();
$identifier = $this->attributeRepository->getIdentifier();
$family->addAttribute($identifier);
$family->setAttributeAsLabel($identifier);
foreach ($this->getChannels() as $channel) {
$requirement = $this->factory->createAttributeRequirement($identifier, $channel, true);
$family->addAttributeRequirement($requirement);
}
return $family;
}
示例14: process
/**
* {@inheritdoc}
*/
public function process($family)
{
$actions = $this->getConfiguredActions();
foreach ($actions as $action) {
$attribute = $this->attributeRepository->findOneByIdentifier($action['attribute_code']);
$channel = $this->channelRepository->findOneByIdentifier($action['channel_code']);
$isRequired = $action['is_required'];
$family->addAttribute($attribute);
$family->addAttributeRequirement($this->factory->createAttributeRequirement($attribute, $channel, $isRequired));
}
return $family;
}
示例15: getPresenterByAttributeCode
/**
* {@inheritdoc}
*/
public function getPresenterByAttributeCode($code)
{
$attribute = $this->attributeRepository->findOneByIdentifier($code);
if (null === $attribute) {
return null;
}
$attributeType = $attribute->getAttributeType();
if (null === $attributeType) {
return null;
}
return $this->getPresenter($attributeType, self::TYPE_PRODUCT_VALUE);
}