src/Model/DataObject/Product/TraitClasses/Checkoutable.php line 150

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