vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Module/Cart.php line 33

Open in your IDE?
  1. <?php
  2. /*
  3.  * Isotope eCommerce for Contao Open Source CMS
  4.  *
  5.  * Copyright (C) 2009 - 2019 terminal42 gmbh & Isotope eCommerce Workgroup
  6.  *
  7.  * @link       https://isotopeecommerce.org
  8.  * @license    https://opensource.org/licenses/lgpl-3.0.html
  9.  */
  10. namespace Isotope\Module;
  11. use Contao\StringUtil;
  12. use Contao\System;
  13. use Haste\Util\Url;
  14. use Isotope\Frontend\ProductCollectionAction\ContinueShoppingAction;
  15. use Isotope\Frontend\ProductCollectionAction\GoToCartAction;
  16. use Isotope\Frontend\ProductCollectionAction\GoToCheckoutAction;
  17. use Isotope\Frontend\ProductCollectionAction\UpdateCartAction;
  18. use Isotope\Interfaces\IsotopeProductCollection;
  19. use Isotope\Isotope;
  20. use Isotope\Model\ProductCollectionItem;
  21. /**
  22.  * @property bool   $iso_continueShopping
  23.  * @property int    $iso_cart_jumpTo
  24.  * @property int    $iso_checkout_jumpTo
  25.  * @property int    $iso_gallery
  26.  * @property string $iso_collectionTpl
  27.  * @property string $iso_orderCollectionBy
  28.  */
  29. class Cart extends AbstractProductCollection
  30. {
  31.     /**
  32.      * Template
  33.      * @var string
  34.      */
  35.     protected $strTemplate 'mod_iso_cart';
  36.     /**
  37.      * Override parent variable for BC reasons
  38.      * @var string
  39.      */
  40.     protected $strFormId 'iso_cart_update_';
  41.     /**
  42.      * @inheritdoc
  43.      */
  44.     protected function compile()
  45.     {
  46.         parent::compile();
  47.         $strCustom '';
  48.         if (isset($GLOBALS['ISO_HOOKS']['compileCart']) && \is_array($GLOBALS['ISO_HOOKS']['compileCart'])) {
  49.             foreach ($GLOBALS['ISO_HOOKS']['compileCart'] as $callback) {
  50.                 $strCustom .= System::importStatic($callback[0])->{$callback[1]}($this);
  51.             }
  52.         }
  53.         $this->Template->custom $strCustom;
  54.     }
  55.     /**
  56.      * @return IsotopeProductCollection
  57.      */
  58.     protected function getCollection()
  59.     {
  60.         return Isotope::getCart();
  61.     }
  62.     /**
  63.      * @return string
  64.      */
  65.     protected function getEmptyMessage()
  66.     {
  67.         return $GLOBALS['TL_LANG']['MSC']['noItemsInCart'];
  68.     }
  69.     /**
  70.      * @return bool
  71.      */
  72.     protected function canEditQuantity()
  73.     {
  74.         return true;
  75.     }
  76.     /**
  77.      * @return bool
  78.      */
  79.     protected function canRemoveProducts()
  80.     {
  81.         return true;
  82.     }
  83.     /**
  84.      * @param IsotopeProductCollection $collection
  85.      * @param array                    $data
  86.      * @param array                    $quantity
  87.      * @param bool                     $hasChanges
  88.      *
  89.      * @return array
  90.      */
  91.     protected function updateItemTemplate(
  92.         IsotopeProductCollection $collection,
  93.         ProductCollectionItem $item,
  94.         array $data,
  95.         array $quantity,
  96.         &$hasChanges
  97.     ) {
  98.         $data parent::updateItemTemplate($collection$item$data$quantity$hasChanges);
  99.         if (isset($data['configuration']) && !$item->hasErrors()) {
  100.             [$baseUrl,] = explode('?'$data['href'], 2);
  101.             $data['edit_href']  = Url::addQueryString('collection_item=' $item->id$baseUrl);
  102.             $data['edit_title'] = StringUtil::specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['editProductLinkTitle'], $data['name']));
  103.             $data['edit_link']  = $GLOBALS['TL_LANG']['MSC']['editProductLinkText'];
  104.         }
  105.         return $data;
  106.     }
  107.     /**
  108.      * {@inheritdoc}
  109.      */
  110.     protected function getActions()
  111.     {
  112.         return [
  113.             new UpdateCartAction(),
  114.             new GoToCartAction($this),
  115.             new GoToCheckoutAction($this),
  116.             new ContinueShoppingAction($this),
  117.         ];
  118.     }
  119. }