In Magento 2 there are two mostly independent pricing calculation sub-sytems. One is used in catalog related calculations and the second one in checkout/order related calculations.
Challenge #1
For checkout/order related calculations, you can start from here: \Magento\Quote\Model\Quote\Item\AbstractItem::isChildrenCalculated
If this method will be returning true
for configurable product and all it's children, you'll see taxes (including FPT) of selected child product(s) to be applied in totals (only children, tax of parent product will be ignored).
Code snippet:
public function isChildrenCalculated()
{
if ($this->getParentItem()) {
$calculate = $this->getParentItem()->getProduct()->getPriceType();
if ($this->getParentItem()->getProduct()->getTypeId() == 'configurable') {
$calculate = 0;
}
} else {
$calculate = $this->getProduct()->getPriceType();
if ($this->getProduct()->getTypeId() == 'configurable') {
$calculate = 0;
}
}
if (null !== $calculate &&
(int)$calculate === \Magento\Catalog\Model\Product\Type\AbstractType::CALCULATE_CHILD
) {
return true;
}
return false;
}
If you need parent product FPT also to be applied, then you need to change \Magento\Weee\Model\Total\Quote\Weee::collect method. As you may notice, there is a conditional code block if ($item->getHasChildren() && $item->isChildrenCalculated()) {
and if children taxes are applied, then parent product tax does not applied. You can fix that by processing parent item as well before or after children taxes being calculated:
Code snippet:
if ($item->getHasChildren() && $item->isChildrenCalculated()) {
foreach ($item->getChildren() as $child) {
$this->resetItemData($child);
$this->process($address, $total, $child);
}
$this->process($address, $total, $item); // calculate for parent as well
$this->recalculateParent($item);
} else {
$this->process($address, $total, $item);
}
I assume, as the most probably, it will be displayed properly only in Shopping Cart Totals section, but not in table for every line items, so you'll need to dig more into Shopping Cart line items renderers, to fix that.
Challenge #2
And as Catalog calculations concerned, you need to fix some JavaScript.
First you need to find a way, how to add children taxes information to the configurable product pricing JSON object.
Code snippet: (\Magento\ConfigurableProduct\Block\Product\View\Type\Configurable::getOptionPrices method):
protected function getOptionPrices()
{
$prices = [];
foreach ($this->getAllowProducts() as $product) {
$priceInfo = $product->getPriceInfo();
$prices[$product->getId()] =
[
'oldPrice' => [
'amount' => $this->_registerJsPrice(
$priceInfo->getPrice('regular_price')->getAmount()->getValue()
),
],
'basePrice' => [
'amount' => $this->_registerJsPrice(
$priceInfo->getPrice('final_price')->getAmount()->getBaseAmount()
),
],
'finalPrice' => [
'amount' => $this->_registerJsPrice(
$priceInfo->getPrice('final_price')->getAmount()->getValue()
),
],
'priceAdjustments' => $this->_registerJsPrice(
$priceInfo->getPrice('final_price')->getAmount()->getAdjustmentAmounts()
)
];
}
return $prices;
}
So, then you can automatically update (Weee: XXX$) block under price block with JavaScript, since 'priceAdjustments' will be now available in JavaScript (app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js). As you may notice here the main challenge is broken modularity. Weee and Tax modules should add the information with some plugin or event. As well as JavaScript manipulations should be performed properly: you need either to have good abstraction around price adjustments, or somehow perform all manipulations not from Catalog or ConfigurableProduct modules JavaScript modules, but from Weee module.
Also, I'm not sure what Weee Tax amount to be displayed on Catalog Product Listing page, but if you need to change how it works now, then it will be Challenge #3 :)
I hope, this will help you to start.