Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PriceModifier.php
Go to the documentation of this file.
1 <?php
8 
11 
13 {
17  protected $productRepository;
18 
22  public function __construct(
24  ) {
25  $this->productRepository = $productRepository;
26  }
27 
38  public function removeTierPrice(\Magento\Catalog\Model\Product $product, $customerGroupId, $qty, $websiteId)
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  }
75 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13
removeTierPrice(\Magento\Catalog\Model\Product $product, $customerGroupId, $qty, $websiteId)
__construct(\Magento\Catalog\Api\ProductRepositoryInterface $productRepository)