22 private $tierPriceFactory;
29 private $tierPricePersistence;
36 private $customerGroupRepository;
43 private $allGroupsValue =
'all groups';
50 private $allGroupsId = 1;
57 private $customerGroupsByCode = [];
69 \
Magento\Catalog\Api\Data\TierPriceInterfaceFactory $tierPriceFactory,
76 $this->tierPricePersistence = $tierPricePersistence;
77 $this->customerGroupRepository = $customerGroupRepository;
79 $this->filterBuilder = $filterBuilder;
89 public function create(array $rawPrice, $sku)
91 $price = $this->tierPriceFactory->create();
92 $price->setPrice(isset($rawPrice[
'percentage_value']) ? $rawPrice[
'percentage_value'] : $rawPrice[
'value']);
94 isset($rawPrice[
'percentage_value'])
95 ? TierPriceInterface::PRICE_TYPE_DISCOUNT
96 : TierPriceInterface::PRICE_TYPE_FIXED
98 $price->setWebsiteId($rawPrice[
'website_id']);
101 $rawPrice[
'all_groups'] == $this->allGroupsId
102 ? $this->allGroupsValue
103 : $this->customerGroupRepository->getById($rawPrice[
'customer_group_id'])->getCode()
105 $price->setQuantity($rawPrice[
'qty']);
120 $this->tierPricePersistence->getEntityLinkField() =>
$id,
121 'all_groups' => $this->retrievePriceForAllGroupsValue(
$price),
122 'customer_group_id' => $this->retrievePriceForAllGroupsValue(
$price) === $this->allGroupsId
124 : $this->retrieveGroupValue(strtolower(
$price->getCustomerGroup())),
125 'qty' =>
$price->getQuantity(),
126 'value' =>
$price->getPriceType() === TierPriceInterface::PRICE_TYPE_FIXED
129 'percentage_value' =>
$price->getPriceType() === TierPriceInterface::PRICE_TYPE_DISCOUNT
132 'website_id' =>
$price->getWebsiteId()
144 return strcasecmp(
$price->getCustomerGroup(), $this->allGroupsValue) === 0 ? $this->allGroupsId : 0;
154 private function retrieveGroupValue(
$code)
156 if (!isset($this->customerGroupsByCode[
$code])) {
159 $this->filterBuilder->setField(
'customer_group_code')->setValue(
$code)->create()
164 $this->customerGroupsByCode[strtolower(
$item->getCode())] =
$item->getId();
167 return $this->customerGroupsByCode[
$code];
__construct(\Magento\Catalog\Api\Data\TierPriceInterfaceFactory $tierPriceFactory, TierPricePersistence $tierPricePersistence, \Magento\Customer\Api\GroupRepositoryInterface $customerGroupRepository, \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder, \Magento\Framework\Api\FilterBuilder $filterBuilder)
createSkeleton(TierPriceInterface $price, $id)
create(array $rawPrice, $sku)