12 use Magento\Catalog\Api\Data\ProductTierPriceExtensionFactory;
90 private $tierPriceExtensionFactory;
110 \
Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
112 \
Magento\Framework\Event\ManagerInterface $eventManager,
117 ProductTierPriceExtensionFactory $tierPriceExtensionFactory =
null 119 $this->_ruleFactory = $ruleFactory;
121 $this->_localeDate = $localeDate;
122 $this->_customerSession = $customerSession;
123 $this->_eventManager = $eventManager;
125 $this->_groupManagement = $groupManagement;
129 ->get(ProductTierPriceExtensionFactory::class);
169 if ($qty ===
null &&
$product->getCalculatedFinalPrice() !==
null) {
170 return $product->getCalculatedFinalPrice();
174 $product->setFinalPrice($finalPrice);
176 $this->_eventManager->dispatch(
'catalog_product_get_final_price', [
'product' =>
$product,
'qty' => $qty]);
178 $finalPrice =
$product->getData(
'final_price');
180 $finalPrice = max(0, $finalPrice);
181 $product->setFinalPrice($finalPrice);
221 return ($returnRawData ?
$prices : []);
235 $value = $this->config->getValue(
'catalog/price/scope', \
Magento\
Store\Model\ScopeInterface::SCOPE_WEBSITE);
238 $websiteId = $this->_storeManager->getWebsite()->getId();
257 $tierPrice =
$product->getTierPrice($qty);
258 if (is_numeric($tierPrice)) {
259 $finalPrice = min($finalPrice, $tierPrice);
285 'website_price' =>
$product->getPrice(),
287 'cust_group' => $allGroupsId,
297 $prevGroup = $allGroupsId;
300 if (
$price[
'cust_group'] != $custGroup &&
$price[
'cust_group'] != $allGroupsId) {
304 if ($qty <
$price[
'price_qty']) {
308 if (
$price[
'price_qty'] < $prevQty) {
312 if (
$price[
'price_qty'] == $prevQty &&
313 $prevGroup != $allGroupsId &&
314 $price[
'cust_group'] == $allGroupsId) {
318 if (
$price[
'website_price'] < $prevPrice) {
319 $prevPrice =
$price[
'website_price'];
320 $prevQty =
$price[
'price_qty'];
321 $prevGroup =
$price[
'cust_group'];
328 if (
$price[
'cust_group'] != $custGroup &&
$price[
'cust_group'] != $allGroupsId) {
331 $priceQty = $qtyCache[
$price[
'price_qty']];
332 if (
$prices[$priceQty][
'website_price'] >
$price[
'website_price']) {
334 $qtyCache[
$price[
'price_qty']] = $priceKey;
339 $qtyCache[
$price[
'price_qty']] = $priceKey;
355 return $this->_groupManagement->getAllCustomersGroup()->getId();
370 $tierPrice = $this->tierPriceFactory->create()
371 ->setExtensionAttributes($this->tierPriceExtensionFactory->create());
372 $tierPrice->setCustomerGroupId(
$price[
'cust_group']);
373 if (array_key_exists(
'website_price',
$price)) {
378 $tierPrice->setValue(
$value);
379 $tierPrice->setQty(
$price[
'price_qty']);
380 if (isset(
$price[
'percentage_value'])) {
381 $tierPrice->getExtensionAttributes()->setPercentageValue(
$price[
'percentage_value']);
384 $tierPrice->getExtensionAttributes()->setWebsiteId(
$websiteId);
416 'website_id' => $priceWebsiteId,
417 'cust_group' =>
$price->getCustomerGroupId(),
418 'website_price' =>
$price->getValue(),
419 'price' =>
$price->getValue(),
420 'all_groups' => (
$price->getCustomerGroupId() == $allGroupsId),
421 'price_qty' =>
$price->getQty(),
436 if (
$product->getCustomerGroupId() !==
null) {
437 return $product->getCustomerGroupId();
439 return $this->_customerSession->getCustomerGroupId();
486 $price[
$index][
'formatted_price'] = $this->priceCurrency->convertAndFormat(
522 return $this->priceCurrency->format(
$product->getFinalPrice());
552 $basePrice = $finalPrice;
555 $confItemOption =
$product->getCustomOption(
'option_' .
$option->getId());
559 ->setConfigurationItemOption($confItemOption);
560 $finalPrice +=
$group->getOptionPrice($confItemOption->getValue(), $basePrice);
591 \Magento\Framework\Profiler::start(
'__PRODUCT_CALCULATE_PRICE__');
592 if ($wId instanceof
Store) {
593 $sId = $wId->getId();
594 $wId = $wId->getWebsiteId();
596 $sId = $this->_storeManager->getWebsite($wId)->getDefaultGroup()->getDefaultStoreId();
599 $finalPrice = $basePrice;
609 if ($rulePrice ===
false) {
610 $date = $this->_localeDate->scopeDate($sId);
611 $rulePrice = $this->_ruleFactory->create()->getRulePrice($date, $wId, $gId,
$productId);
614 if ($rulePrice !==
null && $rulePrice !==
false) {
615 $finalPrice = min($finalPrice, $rulePrice);
618 $finalPrice = max($finalPrice, 0);
619 \Magento\Framework\Profiler::stop(
'__PRODUCT_CALCULATE_PRICE__');
640 if ($specialPrice !==
null && $specialPrice !=
false) {
641 if ($this->_localeDate->isScopeDateInInterval(
$store, $specialPriceFrom, $specialPriceTo)) {
642 $finalPrice = min($finalPrice, $specialPrice);
getTierPriceCount($product)
_applyTierPrice($product, $qty, $finalPrice)
_applyOptionsPrice($product, $qty, $finalPrice)
__construct(\Magento\CatalogRule\Model\ResourceModel\RuleFactory $ruleFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Customer\Model\Session $customerSession, \Magento\Framework\Event\ManagerInterface $eventManager, PriceCurrencyInterface $priceCurrency, GroupManagementInterface $groupManagement, \Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory $tierPriceFactory, \Magento\Framework\App\Config\ScopeConfigInterface $config, ProductTierPriceExtensionFactory $tierPriceExtensionFactory=null)
elseif(isset( $params[ 'redirect_parent']))
getBasePrice($product, $qty=null)
setTierPrices($product, array $tierPrices=null)
getFormattedPrice($product)
getTierPrice($qty, $product)
getFormatedTierPrice($qty, $product)
calculateSpecialPrice( $finalPrice, $specialPrice, $specialPriceFrom, $specialPriceTo, $store=null)
getFinalPrice($qty, $product)
calculatePrice( $basePrice, $specialPrice, $specialPriceFrom, $specialPriceTo, $rulePrice=false, $wId=null, $gId=null, $productId=null)
getChildFinalPrice($product, $productQty, $childProduct, $childProductQty)
getFormatedPrice($product)
getExistingPrices($product, $key, $returnRawData=false)
getFormattedTierPrice($qty, $product)
getWebsiteForPriceScope()
_getCustomerGroupId($product)
_applySpecialPrice($product, $finalPrice)