本文整理汇总了PHP中Pim\Component\Catalog\Repository\AttributeRepositoryInterface::findOneByIdentifier方法的典型用法代码示例。如果您正苦于以下问题:PHP AttributeRepositoryInterface::findOneByIdentifier方法的具体用法?PHP AttributeRepositoryInterface::findOneByIdentifier怎么用?PHP AttributeRepositoryInterface::findOneByIdentifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pim\Component\Catalog\Repository\AttributeRepositoryInterface
的用法示例。
在下文中一共展示了AttributeRepositoryInterface::findOneByIdentifier方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addslashes
function it_sets_invalid_values_to_attributes($validator, $productUpdater, AttributeInterface $attribute, AttributeRepositoryInterface $attributeRepository, ProductInterface $product, ConstraintViolationListInterface $violations, StepExecution $stepExecution, JobConfigurationRepositoryInterface $jobConfigurationRepo, JobExecution $jobExecution, JobConfigurationInterface $jobConfiguration)
{
$stepExecution->getJobExecution()->willReturn($jobExecution);
$jobConfigurationRepo->findOneBy(['jobExecution' => $jobExecution])->willReturn($jobConfiguration);
$values = ['categories' => [['scope' => null, 'locale' => null, 'data' => ['office', 'bedroom']]]];
$normalizedValues = addslashes(json_encode($values));
$jobConfiguration->getConfiguration()->willReturn(json_encode(['filters' => [], 'actions' => ['normalized_values' => $normalizedValues, 'ui_locale' => 'fr_FR', 'attribute_locale' => 'en_US']]));
$validator->validate($product)->willReturn($violations);
$violation = new ConstraintViolation('error2', 'spec', [], '', '', $product);
$violations = new ConstraintViolationList([$violation, $violation]);
$validator->validate($product)->willReturn($violations);
$attributeRepository->findOneByIdentifier('categories')->willReturn($attribute);
$product->isAttributeEditable($attribute)->willReturn(true);
$productUpdater->update($product, $values)->shouldBeCalled();
$this->setStepExecution($stepExecution);
$stepExecution->addWarning(Argument::cetera())->shouldBeCalled();
$stepExecution->incrementSummaryInfo('skipped_products')->shouldBeCalled();
$this->process($product);
}
示例2: 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;
}
示例3: 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);
}
示例4: 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;
}
示例5: 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;
}
示例6:
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);
}
示例7: validate
/**
* {@inheritdoc}
*/
public function validate($attributes, Constraint $constraint)
{
if (null === $attributes || !count($attributes)) {
return;
}
$errorCount = 0;
foreach ($attributes as $attributeCode) {
$attribute = $this->attributeRepository->findOneByIdentifier($attributeCode);
if (null === $attribute) {
$this->context->buildViolation($constraint->message)->setParameter('%attributeCode%', $attributeCode)->atPath(sprintf('[%d]', $errorCount))->addViolation();
$errorCount++;
}
}
}
示例8: setAxis
/**
* @param GroupInterface $group
* @param array $data
*/
protected function setAxis(GroupInterface $group, $data)
{
if (isset($data['axis']) && !empty($data['axis'])) {
$axisCodes = explode(',', $data['axis']);
$attributes = [];
foreach ($axisCodes as $code) {
$attribute = $this->attributeRepository->findOneByIdentifier($code);
if (!$attribute) {
throw new \LogicException(sprintf('Attribute with identifier "%s" not found', $code));
}
$attributes[] = $attribute;
}
$group->setAxisAttributes($attributes);
}
}
示例9: getAttribute
/**
* @param string $code
*
* @return AttributeInterface
*/
protected function getAttribute($code)
{
if (!array_key_exists($code, $this->attributes)) {
$this->attributes[$code] = $this->attributeRepository->findOneByIdentifier($code);
}
return $this->attributes[$code];
}
示例10: process
/**
* {@inheritdoc}
*/
public function process($family)
{
$configuration = $this->getJobConfiguration();
if (!array_key_exists('actions', $configuration)) {
throw new InvalidArgumentException('Missing configuration for \'actions\'.');
}
$actions = $configuration['actions'];
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;
}
示例11: extractColumnInfo
/**
* Extract attribute field name information with attribute code, locale code, scope code
* and optionally price currency
*
* Returned array like:
* [
* "attribute" => AttributeInterface,
* "locale_code" => <locale_code>|null,
* "scope_code" => <scope_code>|null,
* "price_currency" => <currency_code> // this key is optional
* ]
*
* Return null if the field name does not match an attribute.
*
* @param string $fieldName
*
* @return array|null
*/
public function extractColumnInfo($fieldName)
{
if (!isset($this->fieldNameInfoCache[$fieldName]) && !in_array($fieldName, $this->excludedFieldNames)) {
$explodedFieldName = explode(self::FIELD_SEPARATOR, $fieldName);
$attributeCode = $explodedFieldName[0];
$attribute = $this->attributeRepository->findOneByIdentifier($attributeCode);
if (null !== $attribute) {
$this->checkFieldNameTokens($attribute, $fieldName, $explodedFieldName);
$attributeInfo = $this->extractAttributeInfo($attribute, $explodedFieldName);
$this->checkFieldNameLocaleByChannel($attribute, $fieldName, $attributeInfo);
$this->fieldNameInfoCache[$fieldName] = $attributeInfo;
} else {
$this->excludedFieldNames[] = $fieldName;
}
}
return isset($this->fieldNameInfoCache[$fieldName]) ? $this->fieldNameInfoCache[$fieldName] : null;
}
示例12: __construct
/**
* @param AttributeRepositoryInterface $attributeRepository
* @param AttributeOptionRepositoryInterface $attributeOptionRepository
* @param string $attributeCode
* @param FileLoader $loader
* @param string $mappingFile
*/
public function __construct(AttributeRepositoryInterface $attributeRepository, AttributeOptionRepositoryInterface $attributeOptionRepository, $attributeCode, FileLoader $loader = null, $mappingFile = null)
{
$this->attributeRepository = $attributeRepository;
$this->attributeOptionRepository = $attributeOptionRepository;
$this->mapping = [];
$this->attribute = $this->attributeRepository->findOneByIdentifier($attributeCode);
if ($this->attribute) {
$this->attributeOptions = $this->attribute->getOptions();
} else {
$this->attributeOptions = new ArrayCollection();
}
if ($mappingFile !== null && $loader !== null) {
foreach ($loader->load($mappingFile) as $rawValue => $optionCode) {
$this->mapTo($rawValue, $optionCode);
}
}
}
示例13: getNonEligibleAttributes
/**
* Get non eligible attributes to a product template
*
* @param GroupInterface $variantGroup
*
* @return AttributeInterface[]
*/
public function getNonEligibleAttributes(GroupInterface $variantGroup)
{
$attributes = $variantGroup->getAxisAttributes()->toArray();
$template = $variantGroup->getProductTemplate();
if (null !== $template) {
foreach (array_keys($template->getValuesData()) as $attributeCode) {
$attributes[] = $this->attributeRepository->findOneByIdentifier($attributeCode);
}
}
$uniqueAttributes = $this->attributeRepository->findBy(['unique' => true]);
foreach ($uniqueAttributes as $attribute) {
if (!in_array($attribute, $attributes)) {
$attributes[] = $attribute;
}
}
return $attributes;
}
示例14: setAttributeAsLabel
/**
* @param FamilyInterface $family
* @param string $data
*
* @throws \InvalidArgumentException
*/
protected function setAttributeAsLabel(FamilyInterface $family, $data)
{
if (null !== ($attribute = $this->attributeRepository->findOneByIdentifier($data))) {
$family->setAttributeAsLabel($attribute);
} else {
throw new \InvalidArgumentException(sprintf('Attribute with "%s" code does not exist', $data));
}
}
示例15: getAction
/**
* Get attribute by identifier
*
* @param string $identifier
*
* @return JsonResponse
*/
public function getAction($identifier)
{
$attribute = $this->attributeRepository->findOneByIdentifier($identifier);
$attribute = $this->attributeFilter->filterObject($attribute, 'pim.internal_api.attribute.view') ? null : $attribute;
if (null === $attribute) {
throw new NotFoundHttpException(sprintf('Attribute with code "%s" not found', $identifier));
}
return new JsonResponse($this->normalizer->normalize($attribute, 'internal_api'));
}