Skip to content

Commit

Permalink
Merge branch 'fix-issue-36719' of https://github.com/ananth-iyer/mage…
Browse files Browse the repository at this point in the history
…nto2 into fix-issue-36719
  • Loading branch information
ananth-iyer committed May 8, 2023
2 parents 07be698 + cfc48a9 commit 01199a4
Show file tree
Hide file tree
Showing 123 changed files with 6,238 additions and 512 deletions.
119 changes: 85 additions & 34 deletions app/code/Magento/Bundle/Helper/Catalog/Product/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,21 @@
*/
namespace Magento\Bundle\Helper\Catalog\Product;

use Magento\Bundle\Model\Product\Price;
use Magento\Bundle\Model\Product\Type;
use Magento\Bundle\Pricing\Price\TaxPrice;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Helper\Product\Configuration as ProductConfiguration;
use Magento\Catalog\Helper\Product\Configuration\ConfigurationInterface;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Escaper;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Pricing\Helper\Data;
use Magento\Framework\Serialize\Serializer\Json;

/**
* Helper for fetching properties by product configuration item
Expand All @@ -19,61 +31,67 @@ class Configuration extends AbstractHelper implements ConfigurationInterface
/**
* Core data
*
* @var \Magento\Framework\Pricing\Helper\Data
* @var Data
*/
protected $pricingHelper;

/**
* Catalog product configuration
*
* @var \Magento\Catalog\Helper\Product\Configuration
* @var ProductConfiguration
*/
protected $productConfiguration;

/**
* Escaper
*
* @var \Magento\Framework\Escaper
* @var Escaper
*/
protected $escaper;

/**
* Serializer interface instance.
*
* @var \Magento\Framework\Serialize\Serializer\Json
* @var Json
*/
private $serializer;

/**
* @param \Magento\Framework\App\Helper\Context $context
* @param \Magento\Catalog\Helper\Product\Configuration $productConfiguration
* @param \Magento\Framework\Pricing\Helper\Data $pricingHelper
* @param \Magento\Framework\Escaper $escaper
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
* @var TaxPrice
*/
private $taxHelper;

/**
* @param Context $context
* @param ProductConfiguration $productConfiguration
* @param Data $pricingHelper
* @param Escaper $escaper
* @param Json|null $serializer
* @param TaxPrice|null $taxHelper
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Catalog\Helper\Product\Configuration $productConfiguration,
\Magento\Framework\Pricing\Helper\Data $pricingHelper,
\Magento\Framework\Escaper $escaper,
\Magento\Framework\Serialize\Serializer\Json $serializer = null
Context $context,
ProductConfiguration $productConfiguration,
Data $pricingHelper,
Escaper $escaper,
Json $serializer = null,
TaxPrice $taxHelper = null
) {
$this->productConfiguration = $productConfiguration;
$this->pricingHelper = $pricingHelper;
$this->escaper = $escaper;
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Serialize\Serializer\Json::class);
$this->serializer = $serializer ?: ObjectManager::getInstance()
->get(Json::class);
$this->taxHelper = $taxHelper ?? ObjectManager::getInstance()->get(TaxPrice::class);
parent::__construct($context);
}

/**
* Get selection quantity
*
* @param \Magento\Catalog\Model\Product $product
* @param Product $product
* @param int $selectionId
* @return float
*/
public function getSelectionQty(\Magento\Catalog\Model\Product $product, $selectionId)
public function getSelectionQty(Product $product, $selectionId)
{
$selectionQty = $product->getCustomOption('selection_qty_' . $selectionId);
if ($selectionQty) {
Expand All @@ -86,15 +104,15 @@ public function getSelectionQty(\Magento\Catalog\Model\Product $product, $select
* Obtain final price of selection in a bundle product
*
* @param ItemInterface $item
* @param \Magento\Catalog\Model\Product $selectionProduct
* @param Product $selectionProduct
* @return float
*/
public function getSelectionFinalPrice(ItemInterface $item, \Magento\Catalog\Model\Product $selectionProduct)
public function getSelectionFinalPrice(ItemInterface $item, Product $selectionProduct)
{
$selectionProduct->unsetData('final_price');

$product = $item->getProduct();
/** @var \Magento\Bundle\Model\Product\Price $price */
/** @var Price $price */
$price = $product->getPriceModel();

return $price->getSelectionFinalTotalPrice(
Expand All @@ -121,7 +139,7 @@ public function getBundleOptions(ItemInterface $item)
$options = [];
$product = $item->getProduct();

/** @var \Magento\Bundle\Model\Product\Type $typeInstance */
/** @var Type $typeInstance */
$typeInstance = $product->getTypeInstance();

// get bundle options
Expand Down Expand Up @@ -150,16 +168,7 @@ public function getBundleOptions(ItemInterface $item)
$bundleSelections = $bundleOption->getSelections();

foreach ($bundleSelections as $bundleSelection) {
$qty = $this->getSelectionQty($product, $bundleSelection->getSelectionId()) * 1;
if ($qty) {
$option['value'][] = $qty . ' x '
. $this->escaper->escapeHtml($bundleSelection->getName())
. ' '
. $this->pricingHelper->currency(
$this->getSelectionFinalPrice($item, $bundleSelection)
);
$option['has_html'] = true;
}
$option = $this->getOptionPriceHtml($item, $bundleSelection, $option);
}

if ($option['value']) {
Expand All @@ -173,6 +182,48 @@ public function getBundleOptions(ItemInterface $item)
return $options;
}

/**
* Get bundle options' prices
*
* @param ItemInterface $item
* @param ProductInterface $bundleSelection
* @param array $option
* @return array
* @throws LocalizedException
*/
private function getOptionPriceHtml(ItemInterface $item, ProductInterface $bundleSelection, array $option): array
{
$product = $item->getProduct();
$qty = $this->getSelectionQty($item->getProduct(), $bundleSelection->getSelectionId()) * 1;
if ($qty) {
$selectionPrice = $this->getSelectionFinalPrice($item, $bundleSelection);

$displayCartPricesBoth = $this->taxHelper->displayCartPricesBoth();
if ($displayCartPricesBoth) {
$selectionFinalPrice =
$this->taxHelper
->getTaxPrice($product, $selectionPrice, true);
$selectionFinalPriceExclTax =
$this->taxHelper
->getTaxPrice($product, $selectionPrice, false);
} else {
$selectionFinalPrice = $this->taxHelper->getTaxPrice($item->getProduct(), $selectionPrice);
}
$option['value'][] = $qty . ' x '
. $this->escaper->escapeHtml($bundleSelection->getName())
. ' '
. $this->pricingHelper->currency(
$selectionFinalPrice
)
. ($displayCartPricesBoth ? ' ' . __('Excl. tax:') . ' '
. $this->pricingHelper->currency(
$selectionFinalPriceExclTax
) : '');
$option['has_html'] = true;
}
return $option;
}

/**
* Retrieves product options list
*
Expand Down
10 changes: 7 additions & 3 deletions app/code/Magento/Bundle/Model/Plugin/PriceBackend.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<?php

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Bundle\Model\Plugin;

/**
* Class PriceBackend
*
* Make price validation optional for bundle dynamic
* Make price validation optional for bundle dynamic
*/
class PriceBackend
{
/**
* Around validate
*
* @param \Magento\Catalog\Model\Product\Attribute\Backend\Price $subject
* @param \Closure $proceed
* @param \Magento\Catalog\Model\Product|\Magento\Framework\DataObject $object
Expand All @@ -30,6 +33,7 @@ public function aroundValidate(
) {
return true;
}

return $proceed($object);
}
}
Loading

0 comments on commit 01199a4

Please sign in to comment.