diff --git a/vendor/magento/module-weee/Helper/Data.php b/vendor/magento/module-weee/Helper/Data.php index c4d1871383320..e3f018e1c57b5 100644 --- a/vendor/magento/module-weee/Helper/Data.php +++ b/vendor/magento/module-weee/Helper/Data.php @@ -355,7 +355,7 @@ public function getBaseWeeeTaxAppliedRowAmount($item) protected function getRecursiveNumericAmount($item, $functionName) { if ($item instanceof QuoteAbstractItem || $item instanceof OrderItem) { - if ($item->getHasChildren() && $item->isChildrenCalculated()) { + if ($item->getHasChildren()) { $result = 0; $children = $item instanceof OrderItem ? $item->getChildrenItems() : $item->getChildren(); foreach ($children as $child) { @@ -385,7 +385,7 @@ protected function getRecursiveNumericAmount($item, $functionName) public function getApplied($item) { if ($item instanceof QuoteAbstractItem) { - if ($item->getHasChildren() && $item->isChildrenCalculated()) { + if ($item->getHasChildren()) { $result = []; foreach ($item->getChildren() as $child) { $childData = $this->getApplied($child); diff --git a/vendor/magento/module-weee/Model/Tax.php b/vendor/magento/module-weee/Model/Tax.php index 941faed0498f4..f4dbad084f4af 100644 --- a/vendor/magento/module-weee/Model/Tax.php +++ b/vendor/magento/module-weee/Model/Tax.php @@ -6,14 +6,15 @@ namespace Magento\Weee\Model; use Magento\Catalog\Model\Product; +use Magento\ConfigurableProduct\Model\Product\Type\Configurable; use Magento\Framework\Pricing\PriceCurrencyInterface; use Magento\Store\Model\Website; -use Magento\Tax\Model\Calculation; use Magento\Customer\Api\AccountManagementInterface; use Magento\Catalog\Model\Product\Type; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings(PHPMD.CookieAndSessionMisuse) * @api * @since 100.0.2 */ @@ -22,22 +23,22 @@ class Tax extends \Magento\Framework\Model\AbstractModel /** * Including FPT only */ - const DISPLAY_INCL = 0; + public const DISPLAY_INCL = 0; /** * Including FPT and FPT description */ - const DISPLAY_INCL_DESCR = 1; + public const DISPLAY_INCL_DESCR = 1; /** * Excluding FPT. Including FPT description and final price */ - const DISPLAY_EXCL_DESCR_INCL = 2; + public const DISPLAY_EXCL_DESCR_INCL = 2; /** * Excluding FPT */ - const DISPLAY_EXCL = 3; + public const DISPLAY_EXCL = 3; /** * @var array|null @@ -45,8 +46,6 @@ class Tax extends \Magento\Framework\Model\AbstractModel protected $_allAttributes = null; /** - * Tax data - * * @var \Magento\Tax\Helper\Data */ protected $_taxData = null; @@ -71,9 +70,7 @@ class Tax extends \Magento\Framework\Model\AbstractModel */ protected $_customerSession; - /** - * Weee config - * + /**s * @var \Magento\Weee\Model\Config */ protected $weeeConfig; @@ -141,6 +138,8 @@ protected function _construct() } /** + * Retrieve Weee Attribute amount + * * @param Product $product * @param null|false|\Magento\Framework\DataObject $shipping * @param null|false|\Magento\Framework\DataObject $billing @@ -170,6 +169,8 @@ public function getWeeeAmount( } /** + * Retrieve Weee attribute amount excluding tax + * * @param Product $product * @param null|false|\Magento\Framework\DataObject $shipping * @param null|false|\Magento\Framework\DataObject $billing @@ -182,24 +183,32 @@ public function getWeeeAmountExclTax( $billing = null, $website = null ) { + $attributes = []; $amountExclTax = 0; - $attributes = $this->getProductWeeeAttributes( - $product, - $shipping, - $billing, - $website, - true, - false - ); + + if ($product->getTypeId() !== Configurable::TYPE_CODE) { + $attributes = $this->getProductWeeeAttributes( + $product, + $shipping, + $billing, + $website, + true, + false + ); + } + if (Type::TYPE_BUNDLE !== $product->getTypeId() || $product->getPriceType()) { foreach ($attributes as $attribute) { $amountExclTax += $attribute->getAmountExclTax(); } } + return $amountExclTax; } /** + * Retrieve Weee Attribute Codes + * * @param bool $forceEnabled * @return array */ @@ -209,7 +218,7 @@ public function getWeeeAttributeCodes($forceEnabled = false) } /** - * Retrieve Wee tax attribute codes + * Retrieve Weee tax attribute codes * * @param null|string|bool|int|Store $store * @param bool $forceEnabled @@ -228,6 +237,8 @@ public function getWeeeTaxAttributeCodes($store = null, $forceEnabled = false) } /** + * Retrieve product Weee attribute + * * @param Product $product * @param null|false|\Magento\Quote\Model\Quote\Address $shipping * @param null|false|\Magento\Quote\Model\Quote\Address $billing @@ -238,6 +249,7 @@ public function getWeeeTaxAttributeCodes($store = null, $forceEnabled = false) * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * phpcs:disable Generic.Metrics.NestingLevel */ public function getProductWeeeAttributes( $product, @@ -374,6 +386,8 @@ public function getProductWeeeAttributes( } /** + * Check if Weee is in location + * * @param int $countryId * @param int $regionId * @param int $websiteId diff --git a/vendor/magento/module-weee/Model/Total/Quote/Weee.php b/vendor/magento/module-weee/Model/Total/Quote/Weee.php index df33a5c3d8870..5b7c8020d2ca5 100644 --- a/vendor/magento/module-weee/Model/Total/Quote/Weee.php +++ b/vendor/magento/module-weee/Model/Total/Quote/Weee.php @@ -120,12 +120,13 @@ public function collect( continue; } $this->resetItemData($item); - if ($item->getHasChildren() && $item->isChildrenCalculated()) { + if ($item->getHasChildren()) { + $child = null; foreach ($item->getChildren() as $child) { $this->resetItemData($child); $this->process($address, $total, $child); } - $this->recalculateParent($item); + $this->recalculateParent($item, $child); } else { $this->process($address, $total, $item); } @@ -305,11 +306,10 @@ protected function getNextIncrement() /** * Recalculate parent item amounts based on children results * - * @param AbstractItem $item + * @param AbstractItem|null $childItem * @return void - * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - protected function recalculateParent(AbstractItem $item) + protected function recalculateParent(AbstractItem $item, AbstractItem $childItem = null) { $associatedTaxables = []; foreach ($item->getChildren() as $child) { @@ -317,6 +317,11 @@ protected function recalculateParent(AbstractItem $item) } $associatedTaxables = array_merge([], ...$associatedTaxables); $item->setAssociatedTaxables($associatedTaxables); + + if (isset($childItem)) { + $item->setWeeeTaxApplied($childItem->getWeeeTaxApplied()); + $item->setWeeeTaxAppliedAmount($childItem->getWeeeTaxAppliedAmount()); + } } /** diff --git a/vendor/magento/module-weee/Plugin/Catalog/ResourceModel/Product/WeeeAttributeProductSort.php b/vendor/magento/module-weee/Plugin/Catalog/ResourceModel/Product/WeeeAttributeProductSort.php new file mode 100644 index 0000000000000..5e33f7fa2eeae --- /dev/null +++ b/vendor/magento/module-weee/Plugin/Catalog/ResourceModel/Product/WeeeAttributeProductSort.php @@ -0,0 +1,67 @@ +resourceConnection = $resourceConnection; + } + + /** + * Add weee attribute to products sorting query + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * + * @param LinkedProductSelectBuilderByIndexPrice $subject + * @param array $result + * @param int $productId + * @param int $storeId + * @return array + */ + public function afterBuild( + LinkedProductSelectBuilderByIndexPrice $subject, + array $result, + int $productId, + int $storeId + ):array { + $select = $this->resourceConnection->getConnection()->select(); + + foreach ($result as $select) { + $select->columns( + [ + 'weee_min_price' => new \Zend_Db_Expr( + '(t.min_price + IFNULL(weee_child.value, IFNULL(weee_parent.value, 0)))' + ) + ] + )->joinLeft( + ['weee_child' => $this->resourceConnection->getTableName('weee_tax')], + 'weee_child.entity_id = child.entity_id' + )->joinLeft( + ['weee_parent' => $this->resourceConnection->getTableName('weee_tax')], + 'weee_parent.entity_id = parent.entity_id' + )->reset(Select::ORDER)->order('weee_min_price ASC')->limit(1); + } + + return [$select]; + } +} diff --git a/vendor/magento/module-weee/Plugin/ConfigurableProduct/Pricing/FinalPriceResolver.php b/vendor/magento/module-weee/Plugin/ConfigurableProduct/Pricing/FinalPriceResolver.php new file mode 100644 index 0000000000000..b9958c24c89a6 --- /dev/null +++ b/vendor/magento/module-weee/Plugin/ConfigurableProduct/Pricing/FinalPriceResolver.php @@ -0,0 +1,60 @@ +weeeHelperData = $weeeHelperData; + } + + /** + * Display price with weee attribute included + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * + * @param ConfigurableProductFinalPriceResolver $subject + * @param float $result + * @param SaleableInterface $product + * @return float + */ + public function afterResolvePrice( + ConfigurableProductFinalPriceResolver $subject, + float $result, + SaleableInterface $product + ):float { + return $this->weeePriceDisplay() + ? $product->getPriceInfo()->getPrice(CatalogFinalPrice::PRICE_CODE)->getAmount()->getValue() + : $product->getPriceInfo()->getPrice(CatalogFinalPrice::PRICE_CODE)->getValue(); + } + + /** + * Weee including price display + * + * @return bool + */ + private function weeePriceDisplay():bool + { + return $this->weeeHelperData->isDisplayIncl() || $this->weeeHelperData->isDisplayInclDesc(); + } +} diff --git a/vendor/magento/module-weee/Plugin/Model/ConfigurableVariationAttributePriority.php b/vendor/magento/module-weee/Plugin/Model/ConfigurableVariationAttributePriority.php new file mode 100644 index 0000000000000..b866d9c6ea895 --- /dev/null +++ b/vendor/magento/module-weee/Plugin/Model/ConfigurableVariationAttributePriority.php @@ -0,0 +1,79 @@ +productRepository = $productRepository; + $this->configurable = $configurable; + } + + /** + * Apply parent weee attribute for variation w/o weee attribute + * + * @param Tax $subject + * @param array $result + * @param ProductInterface $product + * @param DataObject $shipping + * @param DataObject $billing + * @param string $website + * @param bool $calculateTax + * @param bool $round + * @return array + * @throws \Magento\Framework\Exception\NoSuchEntityException + */ + public function afterGetProductWeeeAttributes( + Tax $subject, + array $result, + ProductInterface $product, + $shipping = null, + $billing = null, + $website = null, + $calculateTax = null, + $round = true + ):array { + if (empty($result)) { + foreach ($this->configurable->getParentIdsByChild($product->getId()) as $parentId) { + $result = $subject->getProductWeeeAttributes( + $this->productRepository->getById($parentId), + $shipping, + $billing, + $website, + $calculateTax, + $round + ); + } + } + + return $result; + } +} diff --git a/vendor/magento/module-weee/etc/di.xml b/vendor/magento/module-weee/etc/di.xml index fa3fafc5a914a..9e611a8630db9 100644 --- a/vendor/magento/module-weee/etc/di.xml +++ b/vendor/magento/module-weee/etc/di.xml @@ -87,4 +87,13 @@ + + + + + + + + +