vendor/isotope/isotope-core/system/modules/isotope/library/Isotope/Collection/ProductPrice.php line 81

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\Collection;
  11. use Isotope\Interfaces\IsotopePrice;
  12. use Isotope\Interfaces\IsotopeProduct;
  13. use Isotope\Isotope;
  14. use Model\Collection;
  15. /**
  16.  * @method \Isotope\Model\ProductPrice current()
  17.  */
  18. class ProductPrice extends Collection implements IsotopePrice
  19. {
  20.     /**
  21.      * Remove duplicate models with the same column value (first model will be kept)
  22.      *
  23.      * @param string $strColumn
  24.      *
  25.      * @return $this
  26.      */
  27.     public function filterDuplicatesBy($strColumn)
  28.     {
  29.         $this->reset();
  30.         $arrFound = array();
  31.         $this->arrModels array_filter(
  32.             $this->arrModels,
  33.             function($objModel) use (&$arrFound$strColumn) {
  34.                 if (isset($arrFound[$objModel->$strColumn])) {
  35.                     return false;
  36.                 }
  37.                 $arrFound[$objModel->$strColumn] = $objModel->id;
  38.                 return true;
  39.             }
  40.         );
  41.         return $this;
  42.     }
  43.     /**
  44.      * Return true if more than one price is available
  45.      *
  46.      * @return bool
  47.      */
  48.     public function hasTiers()
  49.     {
  50.         return $this->current()->hasTiers();
  51.     }
  52.     /**
  53.      * Return lowest tier (= minimum quantity)
  54.      *
  55.      * @return int
  56.      */
  57.     public function getLowestTier()
  58.     {
  59.         return $this->current()->getLowestTier();
  60.     }
  61.     /**
  62.      * Return price
  63.      *
  64.      * @param int   $intQuantity
  65.      * @param array $arrOptions
  66.      *
  67.      * @return float
  68.      */
  69.     public function getAmount($intQuantity 1, array $arrOptions = array())
  70.     {
  71.         return $this->current()->getAmount($intQuantity$arrOptions);
  72.     }
  73.     /**
  74.      * Return original price
  75.      *
  76.      * @param int   $intQuantity
  77.      * @param array $arrOptions
  78.      *
  79.      * @return  float
  80.      */
  81.     public function getOriginalAmount($intQuantity 1, array $arrOptions = array())
  82.     {
  83.         return $this->current()->getOriginalAmount($intQuantity$arrOptions);
  84.     }
  85.     /**
  86.      * Return net price (without taxes)
  87.      *
  88.      * @param int   $intQuantity
  89.      * @param array $arrOptions
  90.      *
  91.      * @return float
  92.      */
  93.     public function getNetAmount($intQuantity 1, array $arrOptions = array())
  94.     {
  95.         return $this->current()->getNetAmount($intQuantity$arrOptions);
  96.     }
  97.     /**
  98.      * Return gross price (with all taxes)
  99.      *
  100.      * @param int   $intQuantity
  101.      * @param array $arrOptions
  102.      *
  103.      * @return float
  104.      */
  105.     public function getGrossAmount($intQuantity 1, array $arrOptions = array())
  106.     {
  107.         return $this->current()->getGrossAmount($intQuantity$arrOptions);
  108.     }
  109.     /**
  110.      * Generate price for HTML rendering
  111.      *
  112.      * @param bool  $blnShowTiers
  113.      * @param int   $intQuantity
  114.      * @param array $arrOptions
  115.      *
  116.      * @return string
  117.      */
  118.     public function generate($blnShowTiers false$intQuantity 1, array $arrOptions = array())
  119.     {
  120.         if (\count($this->arrModels) > 1) {
  121.             $fltPrice           null;
  122.             $fltOriginalPrice   null;
  123.             $arrPrices          = array();
  124.             /** @var \Isotope\Model\ProductPrice $objPrice */
  125.             foreach ($this->arrModels as $objPrice) {
  126.                 $fltNew       $blnShowTiers $objPrice->getLowestAmount($arrOptions) : $objPrice->getAmount($intQuantity$arrOptions);
  127.                 $arrPrices[]  = $fltNew;
  128.                 if (null === $fltPrice || $fltNew $fltPrice) {
  129.                     $fltPrice         $fltNew;
  130.                     $fltOriginalPrice $objPrice->getOriginalAmount($intQuantity$arrOptions);
  131.                 }
  132.             }
  133.             $arrPrices array_unique($arrPrices);
  134.             $blnShowFrom \count($arrPrices) > 1;
  135.             if ($blnShowFrom) {
  136.                 return sprintf($GLOBALS['TL_LANG']['MSC']['priceRangeLabel'], Isotope::formatPriceWithCurrency($fltPrice));
  137.             } elseif ($fltPrice $fltOriginalPrice) {
  138.                 $strPrice         Isotope::formatPriceWithCurrency($fltPrice);
  139.                 $strOriginalPrice Isotope::formatPriceWithCurrency($fltOriginalPrice);
  140.                 return '<div class="original_price"><strike>' $strOriginalPrice '</strike></div><div class="price">' $strPrice '</div>';
  141.             } else {
  142.                 return Isotope::formatPriceWithCurrency($fltPrice);
  143.             }
  144.         } else {
  145.             return $this->current()->generate($blnShowTiers$intQuantity$arrOptions);
  146.         }
  147.     }
  148.     public function setProduct(IsotopeProduct $product)
  149.     {
  150.         foreach ($this->arrModels as $model) {
  151.             if ($model instanceof \Isotope\Model\ProductPrice) {
  152.                 $model->setProduct($product);
  153.             }
  154.         }
  155.     }
  156. }