Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Tierprice Class Reference
Inheritance diagram for Tierprice:
AbstractGroupPrice Price AbstractBackend BackendInterface

Public Member Functions

 __construct (\Magento\Directory\Model\CurrencyFactory $currencyFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Helper\Data $catalogData, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\Locale\FormatInterface $localeFormat, \Magento\Catalog\Model\Product\Type $catalogProductType, \Magento\Customer\Api\GroupManagementInterface $groupManagement, \Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\Tierprice $productAttributeTierprice, ScopeOverriddenValue $scopeOverriddenValue=null)
 
 isScalar ()
 
 validate ($object)
 
- Public Member Functions inherited from AbstractGroupPrice
 __construct (\Magento\Directory\Model\CurrencyFactory $currencyFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Helper\Data $catalogData, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\Locale\FormatInterface $localeFormat, \Magento\Catalog\Model\Product\Type $catalogProductType, GroupManagementInterface $groupManagement, ScopeOverriddenValue $scopeOverriddenValue=null)
 
 validate ($object)
 
 preparePriceData (array $priceData, $productTypeId, $websiteId)
 
 afterLoad ($object)
 
 setPriceData ($object, $priceData)
 
 afterSave ($object)
 
 getAffectedFields ($object)
 
 getResource ()
 
- Public Member Functions inherited from Price
 __construct (\Magento\Directory\Model\CurrencyFactory $currencyFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Helper\Data $catalogData, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\Locale\FormatInterface $localeFormat, ScopeOverriddenValue $scopeOverriddenValue=null)
 
 setAttribute ($attribute)
 
 setScope ($attribute)
 
 validate ($object)
 
- Public Member Functions inherited from AbstractBackend
 setAttribute ($attribute)
 
 getAttribute ()
 
 getType ()
 
 isStatic ()
 
 getTable ()
 
 getEntityIdField ()
 
 setValueId ($valueId)
 
 setEntityValueId ($entity, $valueId)
 
 getValueId ()
 
 getEntityValueId ($entity)
 
 getDefaultValue ()
 
 validate ($object)
 
 afterLoad ($object)
 
 beforeSave ($object)
 
 afterSave ($object)
 
 beforeDelete ($object)
 
 afterDelete ($object)
 
 getAffectedFields ($object)
 
 isScalar ()
 

Protected Member Functions

 _getResource ()
 
 _getAdditionalUniqueFields ($objectArray)
 
 getAdditionalFields ($objectArray)
 
 _getDuplicateErrorMessage ()
 
 _isPriceFixed ($priceObject)
 
 validatePrice (array $priceRow)
 
 modifyPriceData ($object, $data)
 
 updateValues (array $valuesToUpdate, array $oldValues)
 
- Protected Member Functions inherited from AbstractGroupPrice
 _getDuplicateErrorMessage ()
 
 _getWebsiteCurrencyRates ()
 
 _getResource ()
 
 _getAdditionalUniqueFields ($objectArray)
 
 getAdditionalFields ($objectArray)
 
 _isPriceFixed ($priceObject)
 
 validatePrice (array $priceRow)
 
 updateValues (array $valuesToUpdate, array $oldValues)
 
- Protected Member Functions inherited from Price
 isPositiveOrZero ($value)
 

Protected Attributes

 $_productAttributeBackendTierprice
 
- Protected Attributes inherited from AbstractGroupPrice
 $metadataPool
 
 $_rates
 
 $_catalogProductType
 
 $_groupManagement
 
- Protected Attributes inherited from Price
 $_helper
 
 $_storeManager
 
 $_currencyFactory
 
 $_config
 
 $localeFormat
 
- Protected Attributes inherited from AbstractBackend
 $_attribute
 
 $_valueId
 
 $_valueIds = []
 
 $_table
 
 $_entityIdField
 
 $_defaultValue = null
 

Detailed Description

Definition at line 16 of file Tierprice.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Directory\Model\CurrencyFactory  $currencyFactory,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
\Magento\Catalog\Helper\Data  $catalogData,
\Magento\Framework\App\Config\ScopeConfigInterface  $config,
\Magento\Framework\Locale\FormatInterface  $localeFormat,
\Magento\Catalog\Model\Product\Type  $catalogProductType,
\Magento\Customer\Api\GroupManagementInterface  $groupManagement,
\Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\Tierprice  $productAttributeTierprice,
ScopeOverriddenValue  $scopeOverriddenValue = null 
)
Parameters
\Magento\Directory\Model\CurrencyFactory$currencyFactory
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Catalog\Helper\Data$catalogData
\Magento\Framework\App\Config\ScopeConfigInterface$config
\Magento\Framework\Locale\FormatInterface$localeFormat
\Magento\Catalog\Model\Product\Type$catalogProductType
\Magento\Customer\Api\GroupManagementInterface$groupManagement
\Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\Tierprice$productAttributeTierprice
ScopeOverriddenValue | null$scopeOverriddenValue

Definition at line 36 of file Tierprice.php.

46  {
47  $this->_productAttributeBackendTierprice = $productAttributeTierprice;
48  parent::__construct(
49  $currencyFactory,
51  $catalogData,
52  $config,
54  $catalogProductType,
55  $groupManagement,
56  $scopeOverriddenValue
57  );
58  }
$config
Definition: fraud_order.php:17
$storeManager

Member Function Documentation

◆ _getAdditionalUniqueFields()

_getAdditionalUniqueFields (   $objectArray)
protected

Add price qty to unique fields

Parameters
array$objectArray
Returns
array

Definition at line 76 of file Tierprice.php.

77  {
78  $uniqueFields = parent::_getAdditionalUniqueFields($objectArray);
79  $uniqueFields['qty'] = $objectArray['price_qty'] * 1;
80  return $uniqueFields;
81  }

◆ _getDuplicateErrorMessage()

_getDuplicateErrorMessage ( )
protected

Error message when duplicates

Returns
\Magento\Framework\Phrase

Definition at line 100 of file Tierprice.php.

101  {
102  return __('We found a duplicate website, tier price, customer group and quantity.');
103  }
__()
Definition: __.php:13

◆ _getResource()

_getResource ( )
protected

Retrieve resource instance

Returns
\Magento\Catalog\Model\ResourceModel\Product\Attribute\Backend\Tierprice

Definition at line 65 of file Tierprice.php.

◆ _isPriceFixed()

_isPriceFixed (   $priceObject)
protected

Whether tier price value fixed or percent of original price

Parameters
\Magento\Catalog\Model\Product\Type\Price$priceObject
Returns
bool

Definition at line 111 of file Tierprice.php.

112  {
113  return $priceObject->isTierPriceFixed();
114  }

◆ getAdditionalFields()

getAdditionalFields (   $objectArray)
protected

Definition at line 86 of file Tierprice.php.

87  {
88  $percentageValue = $this->getPercentage($objectArray);
89  return [
90  'value' => $percentageValue ? null : $objectArray['price'],
91  'percentage_value' => $percentageValue ?: null,
92  ];
93  }

◆ isScalar()

isScalar ( )

By default attribute value is considered non-scalar that can be stored in a generic way

Returns
bool

Implements BackendInterface.

Definition at line 121 of file Tierprice.php.

122  {
123  return false;
124  }

◆ modifyPriceData()

modifyPriceData (   $object,
  $data 
)
protected

Definition at line 160 of file Tierprice.php.

161  {
162  $data = parent::modifyPriceData($object, $data);
163  $price = $object->getPrice();
164  foreach ($data as $key => $tierPrice) {
165  $percentageValue = $this->getPercentage($tierPrice);
166  if ($percentageValue) {
167  $data[$key]['price'] = $price * (1 - $percentageValue / 100);
168  $data[$key]['website_price'] = $data[$key]['price'];
169  }
170  }
171  return $data;
172  }
$price

◆ updateValues()

updateValues ( array  $valuesToUpdate,
array  $oldValues 
)
protected
Parameters
array$valuesToUpdate
array$oldValues
Returns
boolean

Definition at line 179 of file Tierprice.php.

180  {
181  $isChanged = false;
182  foreach ($valuesToUpdate as $key => $value) {
183  if ((!empty($value['value']) && $oldValues[$key]['price'] != $value['value'])
184  || $this->getPercentage($oldValues[$key]) != $this->getPercentage($value)
185  ) {
186  $price = new \Magento\Framework\DataObject(
187  [
188  'value_id' => $oldValues[$key]['price_id'],
189  'value' => $value['value'],
190  'percentage_value' => $this->getPercentage($value)
191  ]
192  );
193  $this->_getResource()->savePriceData($price);
194 
195  $isChanged = true;
196  }
197  }
198  return $isChanged;
199  }
$price
$value
Definition: gender.phtml:16

◆ validate()

validate (   $object)

Definition at line 129 of file Tierprice.php.

130  {
131  $attribute = $this->getAttribute();
132  $priceRows = $object->getData($attribute->getName());
133  $priceRows = array_filter((array)$priceRows);
134 
135  foreach ($priceRows as $priceRow) {
136  $percentage = $this->getPercentage($priceRow);
137  if ($percentage !== null && (!$this->isPositiveOrZero($percentage) || $percentage > 100)) {
138  throw new \Magento\Framework\Exception\LocalizedException(
139  __('Percentage value must be a number between 0 and 100.')
140  );
141  }
142  }
143 
144  return parent::validate($object);
145  }
__()
Definition: __.php:13

◆ validatePrice()

validatePrice ( array  $priceRow)
protected

Definition at line 150 of file Tierprice.php.

151  {
152  if (!$this->getPercentage($priceRow)) {
153  parent::validatePrice($priceRow);
154  }
155  }

Field Documentation

◆ $_productAttributeBackendTierprice

$_productAttributeBackendTierprice
protected

Definition at line 23 of file Tierprice.php.


The documentation for this class was generated from the following file: