18 private $productRepository;
23 private $storeManager;
33 private $priceModifier;
38 private $tierPriceManagement;
56 $this->priceModifier = $priceModifier;
58 $this->tierPriceManagement = $tierPriceManagement;
66 $product = $this->productRepository->get($sku, [
'edit_mode' =>
true]);
68 $this->prepareTierPrices(
$product->getTierPrices(), $tierPrice)
71 $this->productRepository->save(
$product);
73 throw new \Magento\Framework\Exception\CouldNotSaveException(
__(
"The group price couldn't be saved."));
85 $this->validate($tierPrice);
109 private function getWebsiteId()
111 $websiteIdentifier = 0;
112 $value = $this->config->getValue(
'catalog/price/scope', ScopeInterface::SCOPE_WEBSITE);
114 $websiteIdentifier = $this->storeManager->getWebsite()->getId();
117 return $websiteIdentifier;
125 private function validate(ProductTierPriceInterface $tierPrice)
127 $data = [
'qty' => $tierPrice->getQty(),
'price' => $tierPrice->getValue()];
130 throw new \Magento\Framework\Exception\InputException(
131 __(
'The data was invalid. Verify the data and try again.')
142 $product = $this->productRepository->get($sku, [
'edit_mode' =>
true]);
143 $this->priceModifier->removeTierPrice(
145 $tierPrice->getCustomerGroupId(),
146 $tierPrice->getQty(),
147 $this->getWebsiteId()
155 public function getList($sku, $customerGroupId)
157 return $this->tierPriceManagement->getList($sku, $customerGroupId);
add($sku, ProductTierPriceInterface $tierPrice)
getList($sku, $customerGroupId)
__construct(\Magento\Catalog\Api\ProductRepositoryInterface $productRepository, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\App\Config\ScopeConfigInterface $config, PriceModifier $priceModifier, TierPriceManagement $tierPriceManagement)