yireo-magento1 / Yireo_GoogleTagManager

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

transactionEntity: ORDER always firing? #94

Closed cameraki closed 5 years ago

cameraki commented 6 years ago

Having an issue where transactionEntity: ORDER is firing on every page after an order is being made.

Below is a screenshot of what is being shown my end on every page after an order is made screen shot 2018-07-05 at 10 22 32

I believe this is because in data/order.phtml, it only does the following check:

$order = $this->getOrder();
        if (!empty($order) && $order->getId() > 0) {

Where getOrder() just grabs the last order information:

     /**
     * @return Mage_Sales_Model_Order|null
     */
    public function getOrder()
    {
        $lastOrderId = $this->getLastOrderId();
        if (empty($lastOrderId)) {
            return null;
        }

        $order = Mage::getModel('sales/order')->loadByIncrementId($lastOrderId);
        return $order;
    }

From what I understand this is not correct. The contents of data/order.phtml should only be added to the dataLayer at the checkout success page. Therefore, a check should be added inside data/order.phtml to confirm the page is the success page. Something like if (Mage::app()->getFrontController()->getAction()->getFullActionName() === 'checkout_onepage_success') { at the start of the file.

Just a note, all caching is disabled so I do not believe this is todo with the cache

jissereitsma commented 6 years ago

Thanks for posting. You say that "from what [you] understand [it is] not correct" to add order information to all pages, once that order is placed. I have heard some GA experts say otherwise. But I don't want to debate here. The point is that the PHP code is fine, like it is. If you disagree upon this information being added to all pages, and you want this to be added on just the success-page, isn't the simplest solution to do so through XML layout?

<layout>
    <default>
        <reference name="googletagmanager_data">
            <remove name="googletagmanager_order"/>
        </reference>
    </default>
    <checkout_onepage_success>
        <block type="googletagmanager/data" name="googletagmanager_data" template="googletagmanager/data.phtml">
            <block type="googletagmanager/order" name="googletagmanager_order" template="googletagmanager/data/order.phtml"/>
        </block>
    </checkout_onepage_success>
</layout>

There are numerous GTM implementations out there. But the actual reason why I developed this module is so that you do not have to agree with others on GTM data, but you can simply modify things at will.

Does this work for you?

jajajaime commented 6 years ago

Besides if it is correct or not to show the last order data on every page once an order has been placed, I found an actual issue with showing a new quote. After you place an order, the quote data fails to show up on the page because the getQuote() method is checking for getLastRealOrderId() and returning null if it finds one

/**
     * @return Mage_Sales_Model_Quote|null
     */
    public function getQuote()
    {
        $lastOrderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
        if (!empty($lastOrderId)) {
            return null;
        }

        $quote = Mage::getModel('checkout/cart')->getQuote();
        return $quote;
    }

making all subsequent quotes fail to appear on the page on cart or checkout steps. This is an issue if you want to keep track of a new order being placed on the session.

jissereitsma commented 5 years ago

The functionality of Magento is that the last real order ID is set on the success page and shown on the success page. However, right after this, the session gets a reset, so all quote or order information is gone. This results in people being unable to reset the success page. And this means that the real order ID is gone after the success page has finished loading. If this is not the case, it seems somebody rewrote this part of logic.

If the lines would be gone, as you suggest it, it would mean that the call getQuote() would always deliver a result. But with the last real order ID being present, the call getOrder() would always deliver a result as well (after an order was placed). So which data should be shown?

TBH, this whole issue is separate from the original thread, and it seems not to be the case at other sites. I will close this issue, because the original issue seems to be solved. If there is a new issue, please make sure to open a new Issue.