Skip to content

Commit 993398e

Browse files
author
Rafael Grigorian
committed
Fixed GH-18
1 parent d42e40f commit 993398e

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/app/code/JetRails/Varnish/Observer/AutoPurge.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,17 @@ protected function _purgeOnAllServers ( $target, $purgeChildren = false ) {
9898
return $noErrors;
9999
}
100100

101+
101102
/**
102103
* This method takes in a route and it looks through the rewrites table for all urls that lead
103-
* to said url.
104+
* to said url. It uses a passed store object to determine the base url to use.
104105
* @param String route The route to look for in rewrites table
106+
* @param Object store The store to use for base url
105107
* @return void
106108
*/
107-
protected function _purgeUsingRoute ( $route ) {
109+
protected function _purgeUsingStoreObject ( $route, $store ) {
108110
// Get the base url for the current store
109-
$baseUrl = $this->_storeManager->getStore ()->getBaseUrl ();
111+
$baseUrl = $store->getBaseUrl ();
110112
// Get the category id and retrieve all rewrites recursively and acyclicly.
111113
$rewrites = $this->_purger->getUrlRewrites ( $route );
112114
// Loop through all rewrites
@@ -127,6 +129,25 @@ protected function _purgeUsingRoute ( $route ) {
127129
}
128130
}
129131

132+
/**
133+
* This method takes in a route and determines if the current scope is the "All Stores Scope".
134+
* If it is, then all store views are purged, otherwise just the current one is purged.
135+
* @param String route The route to look for in rewrites table
136+
* @return void
137+
*/
138+
protected function _purgeUsingRoute ( $route ) {
139+
if ( $this->_storeManager->getStore ()->getId () === "0" ) {
140+
$stores = $this->_storeManager->getStores ();
141+
foreach ( $stores as $store ) {
142+
$this->_purgeUsingStoreObject ( $route, $store );
143+
}
144+
}
145+
else {
146+
$store = $this->_storeManager->getStore ();
147+
$this->_purgeUsingStoreObject ( $route, $store );
148+
}
149+
}
150+
130151
/**
131152
* This method is abstract because this class implements the Action class.
132153
* @param Observer observer Observer object passed on dispatch

0 commit comments

Comments
 (0)