11 use Magento\Catalog\Api\Data\ProductTierPriceExtensionFactory;
18 class Price extends \Magento\Catalog\Model\Product\Type\Price
72 \
Magento\Customer\Model\Session $customerSession,
73 \
Magento\Framework\Event\ManagerInterface $eventManager,
78 \
Magento\Catalog\Helper\Data $catalogData,
80 ProductTierPriceExtensionFactory $tierPriceExtensionFactory =
null 82 $this->_catalogData = $catalogData;
95 $tierPriceExtensionFactory
138 $selections =
$product->getTypeInstance()->getSelectionsByIds($selectionIds,
$product);
139 $selections->addTierPriceData();
140 $this->_eventManager->dispatch(
141 'prepare_catalog_product_collection_prices',
142 [
'collection' => $selections,
'store_id' =>
$product->getStoreId()]
144 foreach ($selections->getItems() as $selection) {
145 if ($selection->isSalable()) {
146 $selectionQty =
$product->getCustomOption(
'selection_qty_' . $selection->getSelectionId());
152 $selectionQty->getValue()
172 $selectionIds = $this->serializer->unserialize(
$customOption->getValue());
173 if (is_array($selectionIds) && !empty($selectionIds)) {
174 return $selectionIds;
189 if ($qty ===
null &&
$product->getCalculatedFinalPrice() !==
null) {
190 return $product->getCalculatedFinalPrice();
194 $product->setFinalPrice($finalPrice);
195 $this->_eventManager->dispatch(
'catalog_product_get_final_price', [
'product' =>
$product,
'qty' => $qty]);
196 $finalPrice =
$product->getData(
'final_price');
201 $finalPrice = max(0, $finalPrice);
202 $product->setFinalPrice($finalPrice);
238 $this->_isPricesCalculatedByIndex =
true;
243 $finalPrice =
$product->getFinalPrice();
252 $minPriceFounded =
false;
257 $selections =
$option->getSelections();
259 $selectionMinimalPrices = [];
260 $selectionMaximalPrices = [];
262 foreach (
$option->getSelections() as $selection) {
264 if (!$selection->isSalable()) {
271 $qty = $selection->getSelectionQty();
275 $selectionMinimalPrices[] = $this->_catalogData->getTaxPrice(
287 $selectionMaximalPrices[] = $this->_catalogData->getTaxPrice(
301 if (count($selectionMinimalPrices)) {
302 $selMinPrice = min($selectionMinimalPrices);
305 $minPriceFounded =
true;
306 }
elseif (
true !== $minPriceFounded) {
308 $minPriceFounded =
false === $minPriceFounded ? $selMinPrice : min(
314 if (
$option->isMultiSelection()) {
324 if (!is_bool($minPriceFounded)) {
337 $valuePrice =
$value->getPrice(
true);
352 $maximalValue = array_sum(
$prices);
368 $this->_isPricesCalculatedByIndex =
false;
371 if ($which ==
'max') {
373 }
elseif ($which ==
'min') {
447 $takeTierPrice =
true 449 if (
null === $bundleQty) {
452 if ($selectionQty ===
null) {
453 $selectionQty = $selectionProduct->getSelectionQty();
457 $price = $selectionProduct->getFinalPrice($takeTierPrice ? $selectionQty : 1);
459 if ($selectionProduct->getSelectionPriceType()) {
463 $this->_eventManager->dispatch(
464 'catalog_product_get_final_price',
465 [
'product' =>
$product,
'qty' => $bundleQty]
467 $price =
$product->getData(
'final_price') * ($selectionProduct->getSelectionPriceValue() / 100);
470 $price = $selectionProduct->getSelectionPriceValue();
499 $tierPrice =
$product->getTierPrice($qty);
501 if (is_numeric($tierPrice)) {
502 $tierPrice = $finalPrice - $finalPrice * ($tierPrice / 100);
503 $finalPrice = min($finalPrice, $tierPrice);
520 $allCustomersGroupId = $this->_groupManagement->getAllCustomersGroup()->getId();
537 'website_price' =>
$product->getPrice(),
539 'cust_group' => $allCustomersGroupId,
548 $prevGroup = $allCustomersGroupId;
551 if (empty(
$price[
'percentage_value'])) {
555 if (
$price[
'cust_group'] != $custGroup &&
$price[
'cust_group'] != $allCustomersGroupId) {
559 if ($qty <
$price[
'price_qty']) {
563 if (
$price[
'price_qty'] < $prevQty) {
567 if (
$price[
'price_qty'] == $prevQty
568 && $prevGroup != $allCustomersGroupId
569 &&
$price[
'cust_group'] == $allCustomersGroupId
575 if (
$price[
'percentage_value'] > $prevPrice) {
576 $prevPrice =
$price[
'percentage_value'];
577 $prevQty =
$price[
'price_qty'];
578 $prevGroup =
$price[
'cust_group'];
586 if (
$price[
'cust_group'] != $custGroup &&
$price[
'cust_group'] != $allCustomersGroupId) {
589 $j = $qtyCache[
$price[
'price_qty']];
590 if (
$prices[$j][
'website_price'] <
$price[
'website_price']) {
592 $qtyCache[
$price[
'price_qty']] =
$i;
597 $qtyCache[
$price[
'price_qty']] =
$i;
622 if ($specialPrice !==
null && $specialPrice !=
false) {
623 if ($this->_localeDate->isScopeDateInInterval(
$store, $specialPriceFrom, $specialPriceTo)) {
624 $specialPrice = $finalPrice * ($specialPrice / 100);
625 $finalPrice = min($finalPrice, $specialPrice);
_applyOptionsPrice($product, $qty, $finalPrice)
elseif(isset( $params[ 'redirect_parent']))
calculateSpecialPrice( $finalPrice, $specialPrice, $specialPriceFrom, $specialPriceTo, $store=null)
getSelectionFinalTotalPrice( $bundleProduct, $selectionProduct, $bundleQty, $selectionQty, $multiplyQty=true, $takeTierPrice=true)
getSelectionPrice($bundleProduct, $selectionProduct, $selectionQty=null, $multiplyQty=true)
getBasePrice($product, $qty=null)
getLowestPrice($bundleProduct, $price, $bundleQty=1)
getBundleSelectionIds(\Magento\Catalog\Model\Product $product)
getSelectionPreFinalPrice($bundleProduct, $selectionProduct, $qty=null)
getTotalPrices($product, $which=null, $includeTax=null, $takeTierPrice=true)
getIsPricesCalculatedByIndex()
getFinalPrice($qty, $product)
_applyTierPrice($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, \Magento\Catalog\Helper\Data $catalogData, \Magento\Framework\Serialize\Serializer\Json $serializer=null, ProductTierPriceExtensionFactory $tierPriceExtensionFactory=null)
$_isPricesCalculatedByIndex
getTierPrice($qty, $product)
const OPTION_TYPE_MULTIPLE
const OPTION_TYPE_CHECKBOX
getTotalBundleItemsPrice($product, $qty=null)
_getCustomerGroupId($product)
getChildFinalPrice($product, $productQty, $childProduct, $childProductQty)
_applySpecialPrice($product, $finalPrice)