src/Model/Product/TraitClasses/Checkoutable.php line 125

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Enterprise License (PEL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  * @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  * @license    http://www.pimcore.org/license     GPLv3 and PEL
  13.  */
  14. namespace App\Model\Product\TraitClasses;
  15. use Pimcore\Bundle\EcommerceFrameworkBundle\AvailabilitySystem\AvailabilityInterface;
  16. use Pimcore\Bundle\EcommerceFrameworkBundle\AvailabilitySystem\AvailabilitySystemInterface;
  17. use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
  18. use App\Tool\PimcoreUrl;
  19. trait Checkoutable
  20. {
  21.     /**
  22.      * @return mixed
  23.      */
  24.     public function getOSName() : ?string
  25.     {
  26.         return $this->getName();
  27.     }
  28.     /**
  29.      * @param int $quantityScale
  30.      *
  31.      * @return \Pimcore\Bundle\EcommerceFrameworkBundle\PriceSystem\PriceInterface
  32.      */
  33.     public function getOSPrice($quantityScale 1) : ?\Pimcore\Bundle\EcommerceFrameworkBundle\PriceSystem\PriceInterface
  34.     {
  35.         return $this->getOSPriceInfo($quantityScale)->getPrice();
  36.     }
  37.     /**
  38.      * @return string
  39.      */
  40.     public function getPriceSystemName() : string
  41.     {
  42.         return 'default';
  43.     }
  44.     /**
  45.      * @return \Pimcore\Bundle\EcommerceFrameworkBundle\PriceSystem\PriceSystemInterfac
  46.      */
  47.     public function getPriceSystemImplementation() : \Pimcore\Bundle\EcommerceFrameworkBundle\PriceSystem\PriceSystemInterface
  48.     {
  49.         return Factory::getInstance()->getPriceSystem($this->getPriceSystemName());
  50.     }
  51.     /**
  52.      * @param int $quantityScale
  53.      *
  54.      * @return \Pimcore\Bundle\EcommerceFrameworkBundle\PriceSystem\PriceInfoInterface
  55.      */
  56.     public function getOSPriceInfo($quantityScale 1) : \Pimcore\Bundle\EcommerceFrameworkBundle\PriceSystem\PriceInfoInterface
  57.     {
  58.         return $this->getPriceSystemImplementation()->getPriceInfo($this$quantityScalenull);
  59.     }
  60.     /**
  61.      * @return string
  62.      */
  63.     public function getOSProductNumber() : ?string
  64.     {
  65.         return strval($this->getId());
  66.     }
  67.     /**
  68.      * @return string
  69.      */
  70.     public function getAvailabilitySystemName() : string
  71.     {
  72.         return 'default';
  73.     }
  74.     /**
  75.      * @param int $quantityScale
  76.      *
  77.      * @return bool
  78.      */
  79.     public function getOSIsBookable($quantityScale 1) : bool
  80.     {
  81.         $price $this->getOSPrice($quantityScale);
  82.         return !empty($price) && $this->isActive();
  83.     }
  84.     /**
  85.      * returns instance of availability system implementation based on result of getAvailabilitySystemName()
  86.      *
  87.      * @return AvailabilitySystemInterface|null
  88.      */
  89.     public function getAvailabilitySystemImplementation(): ?AvailabilitySystemInterface
  90.     {
  91.         return Factory::getInstance()->getAvailabilitySystem($this->getAvailabilitySystemName());
  92.     }
  93.     /**
  94.      * returns availability info based on given quantity
  95.      *
  96.      * @param int $quantity
  97.      *
  98.      * @return AvailabilityInterface
  99.      */
  100.     public function getOSAvailabilityInfo($quantity null) : AvailabilityInterface
  101.     {
  102.         return $this->getAvailabilitySystemImplementation()->getAvailabilityInfo($this$quantity);
  103.     }
  104.     /**
  105.      * @param array      $params
  106.      * @param string     $route
  107.      * @param bool|true  $reset
  108.      *
  109.      * @return string
  110.      */
  111.     public function getDetailUrl(array $params = [], $route 'shop-detail'$reset true) : string
  112.     {
  113.         // add id
  114.         if (!array_key_exists('seofriendly'$params)) {
  115.             $params['seofriendly'] = $this->getUrlseofriendly();
  116.         }
  117.         if (!array_key_exists('product'$params)) {
  118.             $params['product'] = $this->getId();
  119.         }
  120.         //add prefix / by default language/shop
  121.         if (!array_key_exists('prefix'$params)) {
  122.             if (isset($params['document']) && $params['document']) {
  123.                 $params['prefix'] = substr($params['document']->getFullPath(), 1);
  124.             } else {
  125.                 $language \Pimcore::getContainer()->get('request_stack')->getCurrentRequest()->getLocale();
  126.                 $params['prefix'] = substr($language02) . '/productos';
  127.             }
  128.         }
  129.         // add name
  130.         if (!array_key_exists('name'$params) && !array_key_exists('category'$params)) {
  131.             // add category path
  132.             $category $this->getFirstCategory();
  133.             if ($category) {
  134.                 $root = ($params['rootCategory']) ?? null;
  135.                 $path $category->getNavigationPath($root$params['document']);
  136.                 $params['category'] = $category->getId();
  137.                 $params['name'] = $path;
  138.             }
  139.             // add name
  140.            // $name = \Pimcore\File::getValidFilename($this->getUrlseofriendly());
  141.            
  142.         }
  143.         //$params['product'] =  $this->getUrlseofriendly() ; // preg_replace('#-{2,}#', '-', $name);
  144.         if (isset($params['rootCategory'])) {
  145.             unset($params['rootCategory']);
  146.         }
  147.         if (isset($params['document'])) {
  148.             unset($params['document']);
  149.         }
  150.         // create url
  151.         $urlHelper \Pimcore::getContainer()->get('App\Tool\PimcoreUrl');
  152.         
  153.         $pimcoreUrl =  $urlHelper->getPimcoreUrl();    
  154.         return str_replace('%prefix' $params['prefix'], $pimcoreUrl->__invoke($params$route$reset));
  155.     }
  156.     /**
  157.      * @param string $thumbnail thumbnail name configured in the Pimcore admin
  158.      *
  159.      * @return string|null
  160.      */
  161.     public function getFirstImage($thumbnail) : ?string
  162.     {
  163.         $firstImageAsset $this->getFirstImageAsset();
  164.         if ($firstImageAsset) {
  165.             return $firstImageAsset->getThumbnail($thumbnail);
  166.         }
  167.         return null;
  168.     }
  169.     /**
  170.      * @param $view
  171.      *
  172.      * @return array
  173.      */
  174.     public function getHeroAttributes($view)
  175.     {
  176.         $heroAttributes = [];
  177.         if ($this->getArtno()) {
  178.             $heroAttributes[] = '<strong>' $view->translate('shop.sku') . ':</strong> ' $this->getArtno();
  179.         }
  180.         if ($this->getEan()) {
  181.             $heroAttributes[] = '<strong>' $view->translate('shop.ean') . ':</strong> ' $this->getEan();
  182.         }
  183.         if ($this->getSize() && $this->getSize() != ' ') {
  184.             $heroAttributes[] = '<strong>' $view->translate('shop.size') . ':</strong> ' $this->getSize();
  185.         }
  186.         if ($this->getColor()) {
  187.             $colors $this->getColor();
  188.             $translatedColors = [];
  189.             foreach ($colors as $c) {
  190.                 $translatedColors[] = $view->translate('optionvalue.' $c);
  191.             }
  192.             $heroAttributes[] = '<strong>' $view->translate('shop.color') . ':</strong> ' .  implode(', '$translatedColors);
  193.         }
  194.         return $heroAttributes;
  195.     }
  196. }