File tree Expand file tree Collapse file tree 5 files changed +38
-20
lines changed
src/app/code/JetRails/Varnish Expand file tree Collapse file tree 5 files changed +38
-20
lines changed Original file line number Diff line number Diff line change 11<?php
22
3- namespace JetRails \Varnish \Observer \Save ;
3+ namespace JetRails \Varnish \Observer \AutoPurge ;
44
55 use JetRails \Varnish \Observer \AutoPurge ;
66 use Magento \Framework \Event \Observer ;
@@ -30,7 +30,9 @@ public function execute ( Observer $observer ) {
3030 if ( $ this ->_data ->isEnabled () && $ this ->_data ->shouldPurgeAfterCategorySave () ) {
3131 // Get id and purge all urls related to route
3232 $ cid = $ observer ->getCategory ()->getId ();
33- $ this ->_purgeUsingRoute ("catalog/category/view/id/ $ cid " );
33+ if ( $ cid !== null ) {
34+ $ this ->_purgeUsingRoute ("catalog/category/view/id/ $ cid " );
35+ }
3436 }
3537 }
3638
Original file line number Diff line number Diff line change 11<?php
22
3- namespace JetRails \Varnish \Observer \Save ;
3+ namespace JetRails \Varnish \Observer \AutoPurge ;
44
55 use JetRails \Varnish \Observer \AutoPurge ;
66 use Magento \Framework \Event \Observer ;
@@ -29,7 +29,9 @@ public function execute ( Observer $observer ) {
2929 if ( $ this ->_data ->isEnabled () && $ this ->_data ->shouldPurgeAfterCmsPageSave () ) {
3030 // Get id and purge all urls related to route
3131 $ pid = $ observer ->getPage ()->getId ();
32- $ this ->_purgeUsingRoute ("cms/page/view/page_id/ $ pid " );
32+ if ( $ pid !== null ) {
33+ $ this ->_purgeUsingRoute ("cms/page/view/page_id/ $ pid " );
34+ }
3335 }
3436 }
3537
Original file line number Diff line number Diff line change 11<?php
22
3- namespace JetRails \Varnish \Observer \Save ;
3+ namespace JetRails \Varnish \Observer \AutoPurge ;
44
55 use JetRails \Varnish \Observer \AutoPurge ;
66 use Magento \Framework \Event \Observer ;
@@ -29,10 +29,12 @@ public function execute ( Observer $observer ) {
2929 if ( $ this ->_data ->isEnabled () && $ this ->_data ->shouldPurgeAfterProductSave () ) {
3030 // Get id and purge all urls related to route
3131 $ pid = $ observer ->getProduct ()->getId ();
32- $ this ->_purgeUsingRoute ("catalog/product/view/id/ $ pid " );
33- // Go through all categories associated with product and purge their urls
34- foreach ( $ observer ->getProduct ()->getCategoryIds () as $ cid ) {
35- $ this ->_purgeUsingRoute ("catalog/category/view/id/ $ cid " );
32+ if ( $ pid !== null ) {
33+ $ this ->_purgeUsingRoute ("catalog/product/view/id/ $ pid " );
34+ // Go through all categories associated with product and purge their urls
35+ foreach ( $ observer ->getProduct ()->getCategoryIds () as $ cid ) {
36+ $ this ->_purgeUsingRoute ("catalog/category/view/id/ $ cid " );
37+ }
3638 }
3739 }
3840 }
Original file line number Diff line number Diff line change 9999 showInStore=" 1" >
100100 <label >Product Save</label >
101101 <source_model >JetRails\Varnish\Model\Adminhtml\Config\Options\YesNo</source_model >
102- <comment >Automatically purge cache for product url and associated categories whenever product is saved.</comment >
102+ <comment >Automatically purge cache for product url and associated categories whenever product is saved/deleted .</comment >
103103 </field >
104104 <field
105105 id=" cms_page_save"
111111 showInStore=" 1" >
112112 <label >CMS Page Save</label >
113113 <source_model >JetRails\Varnish\Model\Adminhtml\Config\Options\YesNo</source_model >
114- <comment >Automatically purge cache for CMS page whenever page is updated .</comment >
114+ <comment >Automatically purge cache for CMS page whenever page is saved .</comment >
115115 </field >
116116 <field
117117 id=" category_save"
123123 showInStore=" 1" >
124124 <label >Category Save</label >
125125 <source_model >JetRails\Varnish\Model\Adminhtml\Config\Options\YesNo</source_model >
126- <comment >Automatically purge cache for category pages whenever category updated .</comment >
126+ <comment >Automatically purge cache for category pages whenever category is saved/deleted .</comment >
127127 </field >
128128 </group >
129129 <group
Original file line number Diff line number Diff line change 2121 instance=" JetRails\Varnish\Observer\Save\Cache"
2222 />
2323 </event >
24- <event name =" catalog_product_save_after " >
24+ <event name =" catalog_product_save_before " >
2525 <observer
26- name=" jetrails_varnish_save_product"
27- instance=" JetRails\Varnish\Observer\Save\Product"
26+ name=" jetrails_varnish_autopurge_product_save"
27+ instance=" JetRails\Varnish\Observer\AutoPurge\Product"
28+ />
29+ </event >
30+ <event name =" catalog_product_delete_before" >
31+ <observer
32+ name=" jetrails_varnish_autopurge_product_delete"
33+ instance=" JetRails\Varnish\Observer\AutoPurge\Product"
2834 />
2935 </event >
3036 <event name =" cms_page_prepare_save" >
3137 <observer
32- name=" jetrails_varnish_save_page"
33- instance=" JetRails\Varnish\Observer\Save\Page"
38+ name=" jetrails_varnish_autopurge_page_save"
39+ instance=" JetRails\Varnish\Observer\AutoPurge\Page"
40+ />
41+ </event >
42+ <event name =" catalog_category_save_before" >
43+ <observer
44+ name=" jetrails_varnish_autopurge_category_save"
45+ instance=" JetRails\Varnish\Observer\AutoPurge\Category"
3446 />
3547 </event >
36- <event name =" catalog_category_save_after " >
48+ <event name =" catalog_category_delete_before " >
3749 <observer
38- name=" jetrails_varnish_save_category "
39- instance=" JetRails\Varnish\Observer\Save \Category"
50+ name=" jetrails_varnish_autopurge_category_delete "
51+ instance=" JetRails\Varnish\Observer\AutoPurge \Category"
4052 />
4153 </event >
4254</config >
You can’t perform that action at this time.
0 commit comments