Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Price on ProductPage event is zero for configurable products #69

Open
ericclaeren opened this issue Oct 21, 2020 · 18 comments
Open

Price on ProductPage event is zero for configurable products #69

ericclaeren opened this issue Oct 21, 2020 · 18 comments

Comments

@ericclaeren
Copy link

Magento version 2.3.5-p2 #:

Edition EE

Expected behavior:

The min price to be displayed for a configurable product.

Actual behavior:

Price is always displayed as 0.

Steps to reproduce:

  1. Visit configurable product page
  2. Inspect Datalayer ProductPage

What happened?

The change was introduced here:
2.4.0...2.5.1#diff-4431d83985d4d014ab1c33820ee280c9ebd92203b337426d3bedb772c2018831R104

It has changed from getFinalPrice() to getPrice() which broke this.

@ericclaeren ericclaeren changed the title Product price on ProductPage event is zero for configurable products Price on ProductPage event is zero for configurable products Oct 21, 2020
@srenon
Copy link
Contributor

srenon commented Oct 21, 2020

@ericclaeren .... sorry about this... I will push a new update shortly

@srenon
Copy link
Contributor

srenon commented Oct 21, 2020

@ericclaeren... please upgrade to the latest version

@srenon srenon closed this as completed Oct 21, 2020
@ericclaeren
Copy link
Author

Wow that was incredibly fast, thanks @srenon.

I'm afraid there's still something not right. I'm was expecting a price with the same amount as shown on the configurable page. Except I'm getting the price excluding VAT. That's probably due to the getBaseAmount() change and not the real final price.

Would you mind looking into that? Thanks

@srenon
Copy link
Contributor

srenon commented Oct 22, 2020

Do you have Opengraph enabled? What price does it show vs our extension?
image

I'm using identical code to what use for Opengraph see

https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Catalog/view/frontend/templates/product/view/opengraph/general.phtml#L18

Can you check the value for $product->getPrice() and $product->getFinalPrice() and let me know if any return the carrect value you are looking for?

@ericclaeren
Copy link
Author

Hi @srenon

OpenGraph is not enabled. This issue is occuring in the datalayer push, not in the part you're showing in the screenshot. Although it uses the same code.

https://github.com/magepal/magento2-google-tag-manager/blob/master/Block/Data/Product.php#L73
https://github.com/magepal/magento2-google-tag-manager/blob/master/Block/Data/Product.php#L88

image

@ericclaeren
Copy link
Author

ericclaeren commented Oct 26, 2020

The initial commit already had logic for simple/configurable based on getFinalPrice() any idea what that was removed? And would reverting that commit won't fix this issue?

22a4b76

@srenon
Copy link
Contributor

srenon commented Oct 26, 2020

@ericclaeren ... It was not working correct for discount/special price

@srenon
Copy link
Contributor

srenon commented Oct 26, 2020

@ericclaeren .... is VAT 15%?

@ericclaeren
Copy link
Author

Hi @srenon No it's 21% in The Netherlands (34.95/121 * 100).
Magento and prices, still don't know every difference. Saw some mentions of price in multiple posts.

https://magento.stackexchange.com/a/235623
Which says final is equal to special, but don't know if that's the case. But also think that getPrice() may not take catalog rules into account.

This post says there isn't one method to get the correct price and depends on the type of product.
https://magento.stackexchange.com/a/283015

Think the last post may be correct, my guess is that you always want to match the price displayed on the page, from my understanding that is the final price, because of the applying of catalog rules and special prices.

@ericclaeren
Copy link
Author

@srenon Are there any developments going concerning this issue? Maybe re-open this issue so other members may participate in providing a solution?

@srenon srenon reopened this Dec 1, 2020
@srenon
Copy link
Contributor

srenon commented Dec 1, 2020

I will figure out a fix for the by the end of the week

@ericclaeren
Copy link
Author

Hi @srenon How are you? Is there any progress on this issue?

@srenon
Copy link
Contributor

srenon commented Feb 12, 2021

@ericclaeren ... Could you let me know if this temporary workaround works?

    /** @var $product ProductInterface */
    if ($this->getProduct()) {
        $price = $this->getProduct()
            ->getPriceInfo()
            ->getPrice(FinalPrice::PRICE_CODE)
            ->getAmount()
            ->getBaseAmount() ?: 0;
    }

    if (!$price) {
        if ($product->getTypeId() == Type::TYPE_SIMPLE) {
            $price = $tm->formatPrice($product->getPrice());
        } else {
            $price = $tm->formatPrice($product->getFinalPrice());
        }
    }

Also, all the other European/vat sites that I have work on does not seem to have this issue

image

image

@srenon
Copy link
Contributor

srenon commented Mar 18, 2021

@ericclaeren ... are you still having issues with the latest release?

@ericclaeren
Copy link
Author

Hi @srenon Sorry I didn't respond earlier.

I have checked the latest release 2.6.0 against the same configurable product and a simple product and now both seem broken or at least don't return the expected display price.

Simple product type:
image

Configurable product type:
image

I have updated all magepal packages, ran setup upgrade and clear all my caches.
composer require magepal/magento2-core magepal/magento2-enhanced-ecommerce magepal/magento2-googletagmanager

The code in 2.5.0 gives the expected result, isn't it possible to just revert to that or test against that code?

@srenon
Copy link
Contributor

srenon commented Mar 26, 2021

If you take a look at https://github.com/magepal/magento2-google-tag-manager/blob/master/Helper/Data.php#L265

If the price is zero then it would use the old logic. So it should be identical to the previous code

public function getProductPrice($product)
{
    $price = 0;

    /** @var $product ProductInterface */
    if ($product) {
        $price = $product
            ->getPriceInfo()
            ->getPrice(FinalPrice::PRICE_CODE)
            ->getAmount()
            ->getBaseAmount() ?: 0;
    }

    if (!$price) {
        if ($product->getTypeId() == Type::TYPE_SIMPLE) {
            $price = $product->getPrice();
        } else {
            $price = $product->getFinalPrice();
        }
    }

    return $this->formatPrice($price);

@ericclaeren
Copy link
Author

ericclaeren commented Mar 29, 2021

Hi @srenon

Yes, that's true, but if the price isn't zero, which is probably the case, the logic is incorrect.
Why don't return to the old logic? That seemed to work.

/** @var $product ProductInterface */
  if ($product = $this->getProduct()) {
      if ($product->getTypeId() == Type::TYPE_SIMPLE) {
          $price = $product->getPrice();
      } else {
          $price = $product->getFinalPrice();
      }
  }

ericclaeren pushed a commit to ericclaeren/magento2-google-tag-manager that referenced this issue Sep 6, 2021
@ericclaeren
Copy link
Author

Hi @srenon After some time away from this issue, ran into this again and decided to search for a possible solution. Could find any cases in which the PR didn't work, but you might have some? In case you do, please let me know.

Cheers, Eric

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants