89 public function add($sku, $customerGroupId,
$price, $qty)
92 throw new InputException(
__(
'The data was invalid. Verify the data and try again.'));
94 $product = $this->productRepository->get($sku, [
'edit_mode' =>
true]);
96 $websiteIdentifier = 0;
97 $value = $this->config->getValue(
'catalog/price/scope', \
Magento\
Store\Model\ScopeInterface::SCOPE_WEBSITE);
99 $websiteIdentifier = $this->storeManager->getWebsite()->getId();
104 if (
'all' == $customerGroupId) {
105 $isGroupValid = (
$item[
'all_groups'] == 1);
107 $isGroupValid = (
$item[
'cust_group'] == $customerGroupId);
110 if ($isGroupValid &&
$item[
'website_id'] == $websiteIdentifier &&
$item[
'price_qty'] == $qty) {
117 $mappedCustomerGroupId =
'all' == $customerGroupId
118 ? $this->groupManagement->getAllCustomersGroup()->getId()
119 : $this->groupRepository->getById($customerGroupId)->getId();
122 'cust_group' => $mappedCustomerGroupId,
124 'website_price' =>
$price,
125 'website_id' => $websiteIdentifier,
133 $errorAttributeCodes = implode(
', ', array_keys(
$errors));
135 __(
'Values in the %1 attributes are invalid. Verify the values and try again.', $errorAttributeCodes)
139 $this->productRepository->save(
$product);
153 public function remove($sku, $customerGroupId, $qty)
155 $product = $this->productRepository->get($sku, [
'edit_mode' =>
true]);
156 $websiteIdentifier = 0;
157 $value = $this->config->getValue(
'catalog/price/scope', \
Magento\
Store\Model\ScopeInterface::SCOPE_WEBSITE);
159 $websiteIdentifier = $this->storeManager->getWebsite()->getId();
161 $this->priceModifier->removeTierPrice(
$product, $customerGroupId, $qty, $websiteIdentifier);
168 public function getList($sku, $customerGroupId)
170 $product = $this->productRepository->get($sku, [
'edit_mode' =>
true]);
172 $priceKey =
'website_price';
173 $value = $this->config->getValue(
'catalog/price/scope', \
Magento\
Store\Model\ScopeInterface::SCOPE_WEBSITE);
178 $cgi = ($customerGroupId ===
'all' 179 ? $this->groupManagement->getAllCustomersGroup()->getId()
184 if ((is_numeric($customerGroupId) && intval(
$price[
'cust_group']) === intval($customerGroupId))
185 || ($customerGroupId ===
'all' &&
$price[
'all_groups'])
188 $tierPrice = $this->priceFactory->create();
189 $tierPrice->setValue(
$price[$priceKey])
190 ->setQty(
$price[
'price_qty'])
191 ->setCustomerGroupId($cgi);
add($sku, $customerGroupId, $price, $qty)
getList($sku, $customerGroupId)
static is($value, $classBaseName, array $args=array(), $namespaces=array())
__construct(ProductRepositoryInterface $productRepository, \Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory $priceFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Product\PriceModifier $priceModifier, \Magento\Framework\App\Config\ScopeConfigInterface $config, GroupManagementInterface $groupManagement, GroupRepositoryInterface $groupRepository)