2

I have been working with project where client requires dynamic pricing to be displayed on each product depending up on customer region and customer type. The issue is when i enable full page cache that price block get cached for every customer and display same price for non logged in and logged in user.

I want to hole punch price.phtml file block but i am unable to find the exact name of same block.

I have tried searching solution everywhere but i haven't found any.

How can i hole punch price block with any full page caching mechanism.

6
  • You can get help here stackoverflow.com/questions/9120413/…
    – Arunendra
    Feb 29, 2016 at 7:39
  • 1
    What full page cache solution are you using? Are we talking Community Edition with a third party FPC? Is so which FPC extension are you using? or a very old Enterprise Edition with native FPC? Feb 29, 2016 at 8:30
  • I am using extendware full page caching module Feb 29, 2016 at 9:15
  • 1
    @KeyurPatel, You can contact to extendware support team. They will solve your problem.
    – Arunendra
    Feb 29, 2016 at 9:31
  • @Arunendra, This is customization as per our requirement, they are not giving any support for personal customization. Feb 29, 2016 at 9:43

1 Answer 1

0

To enhance dynamic functionality in Magento 2 that bypasses the full page cache feature, I have written hole punch feature that may help you to see a working example. (see https://bitbucket.org/magstaging/punchhole for more details

step 1: create a model that implements \Magento\Customer\CustomerData\SectionSourceInterface and implement the function getSectionData

class APIData implements SectionSourceInterface
{
    public function getSectionData()
    {
        return [
            'result'=> $this->getMyCustomerDynamicData()
        ];
    }
}

step 2: define in a frontend di.xml a section node for the model Magento\Customer\CustomerData\SectionPool

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Customer\CustomerData\SectionPool">
        <arguments>
            <argument name="sectionSourceMap" xsi:type="array">
                <item name="dynamic-data" xsi:type="string">Mbs\PunchHole\CustomerData\DynamicData</item>
            </argument>
        </arguments>
    </type>
</config>

step 3: enable the node to be activated with an action (for instance checkout/cart/add

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Customer:etc/sections.xsd">
    <action name="checkout/cart/add">
        <section name="dynamic-data"/>
    </action>
</config>

step 4: create a phtml template that will use your node

<script type="text/x-magento-init">
    {
      "*":{
          "Magento_Ui/js/core/app": {
              "components": {
                  "dynamic-data": {
                      "component":"Mbs_PunchHole/js/jspart"
                  }
              }
          }
      }
    }
</script>

<div data-bind="scope: 'dynamic-data'">
    <div data-bind="text: showMyDynamicResult()"></div>
</div>

step 5: create a js file in view/frontend/web/js/jspart.js

define( [ 'uiComponent', 'Magento_Customer/js/customer-data' ], function (Component, customerData) { 'use strict';

    return Component.extend({
        data: function () {
            const v = customerData.get('dynamic-data');
            return v().result || 0;
        },
        showMyDynamicResult: function () {
            return this.data();
        }
    });
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.