src/Classes/DataMapper/Product/ProductDataMapper.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Classes\DataMapper\Product;
  3. use App\Helper\DataMapper\PriceQuantityValueDataMapper;
  4. use Factory\SupportBundle\Classes\DataMapper\Ecommerce\PriceDataMapper;
  5. use Factory\SupportBundle\Contract\DataMapper\AbstractDataMapper;
  6. use Pimcore\Model\DataObject\Product;
  7. class ProductDataMapper extends AbstractDataMapper
  8. {
  9.     /**
  10.      * @var Product
  11.      */
  12.     protected $resource;
  13.     public function toArray($request)
  14.     {
  15.         $additionals = [];
  16.         if ($additionalContent $this->getAdditionalContent()) {
  17.             $additionals array_filter(
  18.                 ProductAdditionalContentDataMapper::list(
  19.                     $additionalContent->getItems()
  20.                 )->toArray($request)
  21.             );
  22.         }
  23.         $variantImages ProductImageDataMapper::list($this->getProducts() ?? [])->toArray($request);
  24.         if (count($variantImages) > 1) {
  25.             $variantImages array_merge(...$variantImages);
  26.         } elseif (count($variantImages) == 1) {
  27.             $variantImages $variantImages[0];
  28.         } else {
  29.             $variantImages = [];
  30.         }
  31.         return [
  32.             'id' => $this->get('id'),
  33.             'name' => $this->getName(),
  34.             'sku' => $this->getSku(),
  35.             'image' => $this->getMainImage(),
  36.             'href' => $this->getHref(),
  37.             'key' => $this->getKey(),
  38.             'metaTitle' => $this->getMetaTitle(),
  39.             'metaDescription' => $this->getMetaDescription(),
  40.             'metaKeywords' => $this->getMetaKeywords(),
  41.             'ogTitle' => $this->getOgTitle(),
  42.             'ogDescription' => $this->getOgDescription(),
  43.             'ogImage' => $this->getOgImage(),
  44.             'additionalContent' => $additionals,
  45.             'shortDescription' => $this->getShortDescription(),
  46.             'basePrice' => (new PriceQuantityValueDataMapper($this->getBasePrice()))->toArray($request),
  47.             'price' => (new PriceDataMapper($this->getOSPrice()))->toArray($request),
  48.             'minPrice' => (new PriceDataMapper($this->getOSMinPrice()))->toArray($request),
  49.             'isPriceVisible' => $this->getOSPriceInfo()->isPriceVisible(),
  50.             'category' => $this->getMainCategory(),
  51.             'variantImages' => $variantImages,
  52.         ];
  53.     }
  54. }