Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
PriceModifier Class Reference

Public Member Functions

 __construct (\Magento\Catalog\Api\ProductRepositoryInterface $productRepository)
 
 removeTierPrice (\Magento\Catalog\Model\Product $product, $customerGroupId, $qty, $websiteId)
 

Protected Attributes

 $productRepository
 

Detailed Description

Definition at line 12 of file PriceModifier.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Catalog\Api\ProductRepositoryInterface  $productRepository)
Parameters
\Magento\Catalog\Api\ProductRepositoryInterface$productRepository

Definition at line 22 of file PriceModifier.php.

24  {
25  $this->productRepository = $productRepository;
26  }

Member Function Documentation

◆ removeTierPrice()

removeTierPrice ( \Magento\Catalog\Model\Product  $product,
  $customerGroupId,
  $qty,
  $websiteId 
)
Parameters
\Magento\Catalog\Model\Product$product
int | string$customerGroupId
int$qty
int$websiteId
Exceptions

Definition at line 38 of file PriceModifier.php.

39  {
40  $prices = $product->getData('tier_price');
41  // verify if price exist
42  if ($prices === null) {
43  throw new NoSuchEntityException(__('Tier price is unavailable for this product.'));
44  }
45  $tierPricesQty = count($prices);
46 
47  foreach ($prices as $key => $tierPrice) {
48  if ($customerGroupId == 'all' && $tierPrice['price_qty'] == $qty
49  && $tierPrice['all_groups'] == 1 && intval($tierPrice['website_id']) === intval($websiteId)
50  ) {
51  unset($prices[$key]);
52  } elseif ($tierPrice['price_qty'] == $qty && $tierPrice['cust_group'] == $customerGroupId
53  && intval($tierPrice['website_id']) === intval($websiteId)
54  ) {
55  unset($prices[$key]);
56  }
57  }
58 
59  if ($tierPricesQty == count($prices)) {
60  throw new NoSuchEntityException(
61  __(
62  'Product hasn\'t group price with such data: customerGroupId = \'%1\''
63  . ', website = %2, qty = %3',
64  [$customerGroupId, $websiteId, $qty]
65  )
66  );
67  }
68  $product->setData('tier_price', $prices);
69  try {
70  $this->productRepository->save($product);
71  } catch (\Exception $exception) {
72  throw new CouldNotSaveException(__('The tier_price data is invalid. Verify the data and try again.'));
73  }
74  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13

Field Documentation

◆ $productRepository

$productRepository
protected

Definition at line 17 of file PriceModifier.php.


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