yireo-magento1 / Yireo_GoogleTagManager

Implement Google Tag Manager in Magento 1 (deprecated)
Open Software License 3.0
56 stars 46 forks source link

Pricing on configurable products #95

Closed damienwebdev closed 5 years ago

damienwebdev commented 6 years ago

Currently, the price of configurable product children is inaccurate. It renders the price of the parent product for each child. This may be an intentional design decision, but thought I'd report just the same.

See: https://github.com/yireo/Yireo_GoogleTagManager/blob/da473a6320ddb420587897a212fb0d9501d9f5a3/source/app/design/frontend/base/default/template/googletagmanager/data/product.phtml#L48

jissereitsma commented 6 years ago

Does the e-commerce data contain the right price? https://github.com/yireo/Yireo_GoogleTagManager/blob/master/source/app/design/frontend/base/default/template/googletagmanager/data/product.phtml#L68

damienwebdev commented 6 years ago

@jissereitsma Yes it does. But the issue is that not all my "child" configurable products are the same price as their parent configurable product. E.g. a T-shirt has a base price, a XXL T-shirt may cost $1.00 more. Listing the configurable child at the same price results in inaccurate data.

jissereitsma commented 6 years ago

So wouldn't replacing line 48 with the following code fix it or would it not?

$child['price'] = $this->formatPrice($this->getModuleHelper()->getProductPrice($childProduct));
damienwebdev commented 6 years ago

I don't necessarily think so.

If I remember Mage 1 core correctly, configurable "children" don't necessarily pull their prices from their associated simples (this is now the case in Magento 2, thankfully). There's a convoluted middle layer which involves setting the "customOptions".

$product        = Mage::getModel('catalog/product')->load(CONFIG_ID); //configurable product
$childProduct     = Mage::getModel('catalog/product')->load(CONFIG_CHILD_ID); //associated simple product
$confAttributes = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
$pdtOptValues   = array();
foreach ($confAttributes as $attribute) {
    $attrCode    = $attribute['attribute_code'];
    $attrId      = $attribute['attribute_id'];
    $childValue = $childProduct->getData($attrCode);
    $pdtOptValues[$attrId] = $childValue;
}
$product->addCustomOption('attributes', serialize($pdtOptValues));
echo $product->getFinalPrice();

It's a similar process for bundles as well (setting custom options and then calling getFinalPrice)

luxmedia commented 5 years ago
if ($this->formatPrice($this->getModuleHelper()->getProductPrice($childProduct))) {
   $child['price'] = $this->formatPrice($this->getModuleHelper()->getProductPrice($childProduct));
} else {
   $child['price'] = $this->formatPrice($price);
}

@app/design/frontend/base/default/template/googletagmanager/data/product.phtml worked for me.

jissereitsma commented 5 years ago

https://github.com/yireo/Yireo_GoogleTagManager/commit/aac8e2c87a651bdb76ed243790acabd30d65efba

Lex50 commented 5 years ago

productChildren prices appear as 0.00 for configurable product types on a clean install of Magento 1.9.4.1 with Yireo GoogleTagManager 1.5.2.

Screenshot 2019-04-05 at 11 50 59
jissereitsma commented 5 years ago

In a previous Pull Request by a third party contributor, support for Configurable Products was added, but the name and the price was still missing. This has now been added in the latest release.