本文整理汇总了PHP中Pim\Component\Catalog\Repository\AttributeRepositoryInterface::getAttributeTypeByCodes方法的典型用法代码示例。如果您正苦于以下问题:PHP AttributeRepositoryInterface::getAttributeTypeByCodes方法的具体用法?PHP AttributeRepositoryInterface::getAttributeTypeByCodes怎么用?PHP AttributeRepositoryInterface::getAttributeTypeByCodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pim\Component\Catalog\Repository\AttributeRepositoryInterface
的用法示例。
在下文中一共展示了AttributeRepositoryInterface::getAttributeTypeByCodes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resolveMediaPaths
/**
* - Add the media to the $this->writtenFiles to be archive later
* - Update the value of each media in the standard format to add the final path of media in archive.
*
* The standard format for a media contains only the filePath (which is the unique key of the media):
* {
* "values": {
* "picture": [
* {
* "locale": "en_US",
* "scope": "ecommerce",
* "data": [
* "filePath": "a/b/c/d/e/it_s_my_filename.jpg"
* ]
* }
* ]
* }
* }
*
* In exported files, we don't want to see the key, but the original filename. As the standard format does not
* contain this information, we use the Finder() to find the media in the temporary directory created in processor.
*
* After:
* {
* "values": {
* "picture": [
* {
* "locale": "en_US",
* "scope": "ecommerce",
* "data": [
* "filePath": "files/item_identifier/picture/en_US/ecommerce/it's my filename.jpg"
* ]
* }
* ]
* }
* }
*
* @param array $item standard format of an item
* @param string $tmpDirectory directory where media have been copied before to be exported
*
* @return array
*/
protected function resolveMediaPaths(array $item, $tmpDirectory)
{
$attributeTypes = $this->attributeRepository->getAttributeTypeByCodes(array_keys($item['values']));
$mediaAttributeTypes = array_filter($attributeTypes, function ($attributeCode) {
return in_array($attributeCode, $this->mediaAttributeTypes);
});
$identifier = $this->getItemIdentifier($item);
foreach ($mediaAttributeTypes as $attributeCode => $attributeType) {
foreach ($item['values'][$attributeCode] as $index => $value) {
if (null !== $value['data']) {
$exportDirectory = $this->fileExporterPath->generate($value, ['identifier' => $identifier, 'code' => $attributeCode]);
$finder = new Finder();
if (is_dir($tmpDirectory . $exportDirectory)) {
$files = iterator_to_array($finder->files()->in($tmpDirectory . $exportDirectory));
if (!empty($files)) {
$path = $exportDirectory . current($files)->getFilename();
$this->writtenFiles[$tmpDirectory . $path] = $path;
$item['values'][$attributeCode][$index]['data']['filePath'] = $path;
}
}
}
}
}
return $item;
}
示例2: convertLocalizedToDefaultValues
/**
* {@inheritdoc}
*/
public function convertLocalizedToDefaultValues(array $items, array $options = [])
{
$this->violations = new ConstraintViolationList();
$attributeTypes = $this->attributeRepository->getAttributeTypeByCodes(array_keys($items));
foreach ($items as $code => $item) {
if (isset($attributeTypes[$code])) {
$localizer = $this->localizerRegistry->getLocalizer($attributeTypes[$code]);
if (null !== $localizer) {
foreach ($item as $index => $data) {
$items[$code][$index] = $this->convertLocalizedToDefaultValue($localizer, $data, $options, $this->buildPropertyPath($data, $code));
}
}
}
}
return $items;
}
示例3: filter
/**
* {@inheritdoc}
*/
public function filter(ProductInterface $product, array $newValues)
{
$originalValues = $this->getOriginalProduct($product);
$attributeTypes = $this->attributeRepository->getAttributeTypeByCodes(array_keys($newValues));
$result = [];
foreach ($newValues as $code => $value) {
if (in_array($code, $this->productFields)) {
$data = $this->compareField($originalValues, $value, $code);
} elseif (isset($attributeTypes[$code])) {
$data = $this->compareAttribute($originalValues, $value, $attributeTypes, $code);
} else {
throw new \LogicException(sprintf('Cannot filter value of field "%s"', $code));
}
if (null !== $data) {
$result = $this->mergeValueToResult($result, $data);
}
}
return $result;
}
示例4: convertToLocalizedFormats
/**
* {@inheritdoc}
*
* Before:
* [
* "name": [{
* "locale": "fr_FR",
* "scope": null,
* "data": "T-shirt super beau",
* }],
* "price": [
* {
* "locale": null,
* "scope": ecommerce,
* "data": [
* {"data": 10.78, "currency": "EUR"},
* {"data": 24, "currency": "USD"},
* {"data": 20.75, "currency": "CHF"}
* ]
* }
* ],
* "length": [{
* "locale": "en_US",
* "scope": "mobile",
* "data": {"data": 10.45, "unit": "CENTIMETER"}
* }]
* [...]
*
* After:
* [
* "name": [{
* "locale": "fr_FR",
* "scope": null,
* "data": "T-shirt super beau",
* }],
* "price": [
* {
* "locale": null,
* "scope": ecommerce,
* "data": [
* {"data": "10,78", "currency": "EUR"},
* {"data": "24", "currency": "USD"},
* {"data": "20,75", "currency": "CHF"}
* ]
* }
* ],
* "length": [{
* "locale": "en_US",
* "scope": "mobile",
* "data": {"data": "10,45", "unit": "CENTIMETER"}
* }]
* [...]
*/
public function convertToLocalizedFormats(array $items, array $options = [])
{
$attributeTypes = $this->attributeRepository->getAttributeTypeByCodes(array_keys($items));
foreach ($items as $code => $item) {
if (isset($attributeTypes[$code])) {
$localizer = $this->localizerRegistry->getLocalizer($attributeTypes[$code]);
if (null !== $localizer) {
foreach ($item as $index => $data) {
$items[$code][$index]['data'] = $localizer->localize($data['data'], $options);
}
}
}
}
return $items;
}