Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TierPrice.php
Go to the documentation of this file.
1 <?php
8 
12 
17 {
21  protected $filterByBasePrice = false;
22 
26  protected $percent;
27 
33  public function getDiscountPercent()
34  {
35  if ($this->percent === null) {
36  $prices = $this->getStoredTierPrices();
38  $this->value = $prevPrice = false;
39  $priceGroup = $this->groupManagement->getAllCustomersGroup()->getId();
40 
41  foreach ($prices as $price) {
42  if (!$this->canApplyTierPrice($price, $priceGroup, $prevQty)
43  || !isset($price['percentage_value'])
44  || !is_numeric($price['percentage_value'])
45  ) {
46  continue;
47  }
48  if (false === $prevPrice || $this->isFirstPriceBetter($price['website_price'], $prevPrice)) {
49  $prevPrice = $price['website_price'];
50  $prevQty = $price['price_qty'];
51  $priceGroup = $price['cust_group'];
52  $this->percent = max(0, min(100, 100 - $price['percentage_value']));
53  }
54  }
55  }
56  return $this->percent;
57  }
58 
64  public function getValue()
65  {
66  if ($this->value !== null) {
67  return $this->value;
68  }
69 
70  $tierPrice = $this->getDiscountPercent();
71  if ($tierPrice) {
72  $regularPrice = $this->getRegularPrice();
73  $this->value = $regularPrice * ($tierPrice / 100);
74  } else {
75  $this->value = false;
76  }
77  return $this->value;
78  }
79 
85  protected function getRegularPrice()
86  {
87  return $this->priceInfo->getPrice(RegularPrice::PRICE_CODE)->getValue();
88  }
89 
99  protected function isFirstPriceBetter($firstPrice, $secondPrice)
100  {
101  return $firstPrice > $secondPrice;
102  }
103 
107  public function isPercentageDiscount()
108  {
109  return true;
110  }
111 }
$block setTitle( 'CMS Block Title') -> setIdentifier('fixture_block') ->setContent('< h1 >Fixture Block Title</h1 >< a href=" store url</a><p> Config value
Definition: block.php:9
canApplyTierPrice(array $currentTierPrice, $prevPriceGroup, $prevQty)
Definition: TierPrice.php:251
$price
isFirstPriceBetter($firstPrice, $secondPrice)
Definition: TierPrice.php:99