当前位置: 首页>>代码示例>>PHP>>正文


PHP AttributeRepositoryInterface::getAttributeTypeByCodes方法代码示例

本文整理汇总了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;
 }
开发者ID:a2xchip,项目名称:pim-community-dev,代码行数:67,代码来源:AbstractItemMediaWriter.php

示例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;
 }
开发者ID:alexisfroger,项目名称:pim-community-dev,代码行数:19,代码来源:LocalizedAttributeConverter.php

示例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;
 }
开发者ID:a2xchip,项目名称:pim-community-dev,代码行数:22,代码来源:ProductFilter.php

示例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;
 }
开发者ID:a2xchip,项目名称:pim-community-dev,代码行数:68,代码来源:AttributeConverter.php


注:本文中的Pim\Component\Catalog\Repository\AttributeRepositoryInterface::getAttributeTypeByCodes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。