Sitewards_B2BProfessional - Version 3.0.1

Version Notes

Fix an issue with simple products shown as "Out of stock" on product listings but showing "In Stock" on the product details page.

Download this release

Release Info

Developer Sitewards Magento Team
Extension Sitewards_B2BProfessional
Version 3.0.1
Comparing to
See all releases


Code changes from version 3.0.0 to 3.0.1

app/code/community/Sitewards/B2BProfessional/Model/Observer.php CHANGED
@@ -3,9 +3,10 @@
3
  /**
4
  * Sitewards_B2BProfessional_Model_Observer
5
  * - Observer containing the following event methods
6
- * - catalog_product_is_salable_after - remove add to cart buttons,
7
- * - catalog_product_type_prepare_full_options - stop product being added to cart via url
8
- * - core_block_abstract_to_html_after - remove price from product pages
 
9
  *
10
  * @category Sitewards
11
  * @package Sitewards_B2BProfessional
@@ -20,6 +21,44 @@ class Sitewards_B2BProfessional_Model_Observer
20
  */
21
  protected static $iLastProductId = 0;
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  /**
24
  * Check to see if a product can be sold to the current logged in user
25
  * - if the flag of salable is already false then we should do nothing
@@ -28,15 +67,9 @@ class Sitewards_B2BProfessional_Model_Observer
28
  */
29
  public function catalogProductIsSalableAfter(Varien_Event_Observer $oObserver)
30
  {
31
- /** @var Sitewards_B2BProfessional_Helper_Data $oB2BHelper */
32
- $oB2BHelper = Mage::helper('sitewards_b2bprofessional');
33
- if ($oB2BHelper->isExtensionActive() === true) {
34
- $oProduct = $oObserver->getEvent()->getProduct();
35
- $oSalable = $oObserver->getEvent()->getSalable();
36
-
37
- if ($oSalable->getIsSalable() == true) {
38
- $oSalable->setIsSalable($oB2BHelper->isProductActive($oProduct));
39
- }
40
  }
41
  }
42
 
@@ -48,13 +81,11 @@ class Sitewards_B2BProfessional_Model_Observer
48
  */
49
  public function catalogProductTypePrepareFullOptions(Varien_Event_Observer $oObserver)
50
  {
51
- /** @var Sitewards_B2BProfessional_Helper_Data $oB2BHelper */
52
- $oB2BHelper = Mage::helper('sitewards_b2bprofessional');
53
- if ($oB2BHelper->isExtensionActive() === true) {
54
- $oProduct = $oObserver->getEvent()->getProduct();
55
 
56
- if ($oB2BHelper->isProductActive($oProduct) === false) {
57
- throw new Mage_Catalog_Exception($oB2BHelper->__('Your account is not allowed to access this store.'));
58
  }
59
  }
60
  }
@@ -66,9 +97,7 @@ class Sitewards_B2BProfessional_Model_Observer
66
  */
67
  public function coreBlockAbstractToHtmlAfter(Varien_Event_Observer $oObserver)
68
  {
69
- /** @var Sitewards_B2BProfessional_Helper_Data $oB2BHelper */
70
- $oB2BHelper = Mage::helper('sitewards_b2bprofessional');
71
- if ($oB2BHelper->isExtensionActive() === true) {
72
  $oBlock = $oObserver->getData('block');
73
  $oTransport = $oObserver->getData('transport');
74
 
@@ -88,9 +117,7 @@ class Sitewards_B2BProfessional_Model_Observer
88
  */
89
  public function controllerActionPredispatch(Varien_Event_Observer $oObserver)
90
  {
91
- /** @var Sitewards_B2BProfessional_Helper_Data $oB2BHelper */
92
- $oB2BHelper = Mage::helper('sitewards_b2bprofessional');
93
- if ($oB2BHelper->isExtensionActive() === true) {
94
  /* @var $oControllerAction Mage_Core_Controller_Front_Action */
95
  $oControllerAction = $oObserver->getData('controller_action');
96
 
@@ -114,9 +141,7 @@ class Sitewards_B2BProfessional_Model_Observer
114
  */
115
  public function coreBlockAbstractToHtmlBefore(Varien_Event_Observer $oObserver)
116
  {
117
- /** @var Sitewards_B2BProfessional_Helper_Data $oB2BHelper */
118
- $oB2BHelper = Mage::helper('sitewards_b2bprofessional');
119
- if ($oB2BHelper->isExtensionActive() === true) {
120
  $oBlock = $oObserver->getData('block');
121
 
122
  if ($oBlock instanceof Mage_Catalog_Block_Product_List_Toolbar) {
@@ -133,14 +158,12 @@ class Sitewards_B2BProfessional_Model_Observer
133
  */
134
  public function coreLayoutBlockCreateAfter(Varien_Event_Observer $oObserver)
135
  {
136
- /* @var Sitewards_B2BProfessional_Helper_Data $oB2BHelper */
137
- $oB2BHelper = Mage::helper('sitewards_b2bprofessional');
138
- if ($oB2BHelper->isExtensionActive()) {
139
  $oBlock = $oObserver->getData('block');
140
  if ($oBlock instanceof Mage_Catalog_Block_Layer_View) {
141
  $aCategoryOptions = $this->getCategoryFilters($oBlock);
142
 
143
- if ($oB2BHelper->hasEnabledCategories($aCategoryOptions)) {
144
  $this->removePriceFilter($oBlock);
145
  }
146
  }
@@ -155,8 +178,7 @@ class Sitewards_B2BProfessional_Model_Observer
155
  */
156
  protected function isExactlyPriceBlock($oBlock)
157
  {
158
- return $oBlock
159
- && Mage::helper('sitewards_b2bprofessional')->isBlockPriceBlock($oBlock);
160
  }
161
 
162
  /**
@@ -252,20 +274,44 @@ class Sitewards_B2BProfessional_Model_Observer
252
  */
253
  protected function transformPriceBlock($oBlock, $oTransport)
254
  {
255
- /** @var Sitewards_B2BProfessional_Helper_Data $oB2BHelper */
256
- $oB2BHelper = Mage::helper('sitewards_b2bprofessional');
257
  $oProduct = $oBlock->getProduct();
258
  $iCurrentProductId = $oProduct->getId();
259
 
260
- if ($oB2BHelper->isProductActive($oProduct) === false) {
261
  // To stop duplicate information being displayed validate that we only do this once per product
262
  if ($iCurrentProductId !== self::$iLastProductId) {
263
  self::$iLastProductId = $iCurrentProductId;
264
- $oTransport->setHtml($oB2BHelper->__('Please login'));
265
  } else {
266
  $oTransport->setHtml('');
267
  }
268
  $this->setSymmetricsProductType($oProduct);
269
  }
270
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
  }
3
  /**
4
  * Sitewards_B2BProfessional_Model_Observer
5
  * - Observer containing the following event methods
6
+ * - catalog_product_load_after - displays the correct stock status text on all products,
7
+ * - catalog_product_is_salable_after - remove add to cart buttons,
8
+ * - catalog_product_type_prepare_full_options - stop product being added to cart via url,
9
+ * - core_block_abstract_to_html_after - remove price from product pages,
10
  *
11
  * @category Sitewards
12
  * @package Sitewards_B2BProfessional
21
  */
22
  protected static $iLastProductId = 0;
23
 
24
+ /**
25
+ * The b2b prof helper class
26
+ *
27
+ * @var Sitewards_B2BProfessional_Helper_Data
28
+ */
29
+ protected $oB2BHelper;
30
+
31
+ /**
32
+ * Init the helper object
33
+ */
34
+ public function __construct()
35
+ {
36
+ $this->oB2BHelper = Mage::helper('sitewards_b2bprofessional');
37
+ }
38
+
39
+ /**
40
+ * Check if the extension is active
41
+ *
42
+ * @return bool
43
+ */
44
+ protected function isExtensionActive()
45
+ {
46
+ return $this->oB2BHelper->isExtensionActive();
47
+ }
48
+
49
+ /**
50
+ * This will cover the case where the event 'catalog_product_is_salable_after' has not been called yet
51
+ * - In the same data provided by magento the "swiss-movement-sports-watch" causes this issue
52
+ *
53
+ * @param Varien_Event_Observer $oObserver
54
+ */
55
+ public function catalogProductLoadAfter(Varien_Event_Observer $oObserver)
56
+ {
57
+ if ($this->isExtensionActive()) {
58
+ $this->setSalable($oObserver);
59
+ }
60
+ }
61
+
62
  /**
63
  * Check to see if a product can be sold to the current logged in user
64
  * - if the flag of salable is already false then we should do nothing
67
  */
68
  public function catalogProductIsSalableAfter(Varien_Event_Observer $oObserver)
69
  {
70
+ if ($this->isExtensionActive()) {
71
+ $this->setSalable($oObserver);
72
+ $this->setSalable($oObserver, 'salable');
 
 
 
 
 
 
73
  }
74
  }
75
 
81
  */
82
  public function catalogProductTypePrepareFullOptions(Varien_Event_Observer $oObserver)
83
  {
84
+ if ($this->isExtensionActive()) {
85
+ $oProduct = $this->getEventsProduct($oObserver);
 
 
86
 
87
+ if ($this->oB2BHelper->isProductActive($oProduct) === false) {
88
+ throw new Mage_Catalog_Exception($this->oB2BHelper->__('Your account is not allowed to access this store.'));
89
  }
90
  }
91
  }
97
  */
98
  public function coreBlockAbstractToHtmlAfter(Varien_Event_Observer $oObserver)
99
  {
100
+ if ($this->isExtensionActive()) {
 
 
101
  $oBlock = $oObserver->getData('block');
102
  $oTransport = $oObserver->getData('transport');
103
 
117
  */
118
  public function controllerActionPredispatch(Varien_Event_Observer $oObserver)
119
  {
120
+ if ($this->isExtensionActive()) {
 
 
121
  /* @var $oControllerAction Mage_Core_Controller_Front_Action */
122
  $oControllerAction = $oObserver->getData('controller_action');
123
 
141
  */
142
  public function coreBlockAbstractToHtmlBefore(Varien_Event_Observer $oObserver)
143
  {
144
+ if ($this->isExtensionActive()) {
 
 
145
  $oBlock = $oObserver->getData('block');
146
 
147
  if ($oBlock instanceof Mage_Catalog_Block_Product_List_Toolbar) {
158
  */
159
  public function coreLayoutBlockCreateAfter(Varien_Event_Observer $oObserver)
160
  {
161
+ if ($this->isExtensionActive()) {
 
 
162
  $oBlock = $oObserver->getData('block');
163
  if ($oBlock instanceof Mage_Catalog_Block_Layer_View) {
164
  $aCategoryOptions = $this->getCategoryFilters($oBlock);
165
 
166
+ if ($this->oB2BHelper->hasEnabledCategories($aCategoryOptions)) {
167
  $this->removePriceFilter($oBlock);
168
  }
169
  }
178
  */
179
  protected function isExactlyPriceBlock($oBlock)
180
  {
181
+ return $oBlock && $this->oB2BHelper->isBlockPriceBlock($oBlock);
 
182
  }
183
 
184
  /**
274
  */
275
  protected function transformPriceBlock($oBlock, $oTransport)
276
  {
 
 
277
  $oProduct = $oBlock->getProduct();
278
  $iCurrentProductId = $oProduct->getId();
279
 
280
+ if ($this->oB2BHelper->isProductActive($oProduct) === false) {
281
  // To stop duplicate information being displayed validate that we only do this once per product
282
  if ($iCurrentProductId !== self::$iLastProductId) {
283
  self::$iLastProductId = $iCurrentProductId;
284
+ $oTransport->setHtml($this->oB2BHelper->__('Please login'));
285
  } else {
286
  $oTransport->setHtml('');
287
  }
288
  $this->setSymmetricsProductType($oProduct);
289
  }
290
  }
291
+
292
+ /**
293
+ * Get the product attached to an event
294
+ *
295
+ * @param Varien_Event_Observer $oObserver
296
+ * @return Mage_Catalog_Model_Product
297
+ */
298
+ protected function getEventsProduct(Varien_Event_Observer $oObserver)
299
+ {
300
+ return $oObserver->getProduct();
301
+ }
302
+
303
+ /**
304
+ * Set the salable data on a given object
305
+ *
306
+ * @param Varien_Event_Observer $oObserver
307
+ * @param string $sObjectName
308
+ */
309
+ protected function setSalable(Varien_Event_Observer $oObserver, $sObjectName = 'product')
310
+ {
311
+ $oProduct = $this->getEventsProduct($oObserver);
312
+ $oObject = $oObserver->getData($sObjectName);
313
+ if ($oObject !== null && $oObject->getIsSalable() == true) {
314
+ $oObject->setIsSalable($this->oB2BHelper->isProductActive($oProduct));
315
+ }
316
+ }
317
  }
app/code/community/Sitewards/B2BProfessional/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Sitewards_B2BProfessional>
5
- <version>3.0.0</version>
6
  </Sitewards_B2BProfessional>
7
  </modules>
8
  <global>
@@ -19,6 +19,15 @@
19
  </global>
20
  <frontend>
21
  <events>
 
 
 
 
 
 
 
 
 
22
  <catalog_product_is_salable_after>
23
  <observers>
24
  <sitewards_b2bprofessional>
2
  <config>
3
  <modules>
4
  <Sitewards_B2BProfessional>
5
+ <version>3.0.1</version>
6
  </Sitewards_B2BProfessional>
7
  </modules>
8
  <global>
19
  </global>
20
  <frontend>
21
  <events>
22
+ <catalog_product_load_after>
23
+ <observers>
24
+ <sitewards_b2bprofessional>
25
+ <type>singleton</type>
26
+ <class>sitewards_b2bprofessional/observer</class>
27
+ <method>catalogProductLoadAfter</method>
28
+ </sitewards_b2bprofessional>
29
+ </observers>
30
+ </catalog_product_load_after>
31
  <catalog_product_is_salable_after>
32
  <observers>
33
  <sitewards_b2bprofessional>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Sitewards_B2BProfessional</name>
4
- <version>3.0.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/gpl-license.php">GPL</license>
7
  <channel>community</channel>
@@ -20,11 +20,11 @@ Features of the B2BProfessional Extension:&#xD;
20
  &#xB7; Activation for specific product categories&#xD;
21
  &#xB7; Activation for specific customer groups&#xD;
22
  &#xB7; Optional require login to access store</description>
23
- <notes>Updated the extension to improve code quality and extension speed.</notes>
24
  <authors><author><name>Sitewards Magento Team</name><user>sitewards</user><email>magento@sitewards.com</email></author></authors>
25
- <date>2014-08-15</date>
26
- <time>14:14:24</time>
27
- <contents><target name="magecommunity"><dir name="Sitewards"><dir name="B2BProfessional"><dir name="Docs"><file name="Sitewards B2B Professional_Deutsch V4.pdf" hash="69c5aabb9eba3cb4d060206f68bfffa9"/><file name="Sitewards B2B Professional_ENG_V4.pdf" hash="ec57137d81856521207e5014dfad133d"/></dir><dir name="Helper"><file name="Category.php" hash="72689cd7ea584379faf651d5dab7c351"/><file name="Core.php" hash="42335338c141593bc65b1e7913e4faf1"/><file name="Customer.php" hash="66f0f771c367e84181392f08efd693a4"/><file name="Data.php" hash="986044678c3628e854048d3e41c4e51e"/><file name="Redirects.php" hash="4b6d65cbf94a58b8b8b74eb480075fed"/></dir><dir name="Model"><file name="Observer.php" hash="5b2c913136e1337e6858103185855841"/><dir name="System"><dir name="Config"><dir name="Source"><file name="Category.php" hash="c45ee6c8eaaec42d239705b591c77919"/><file name="Page.php" hash="4527fdfc9bba40aa98dffc6db8fa5d3e"/></dir></dir></dir></dir><dir name="Test"><dir name="Helper"><dir name="Data"><dir name="fixtures"><file name="testIsExtensionActive.yaml" hash="1597dbaa9909bf2cd6cdc41188d79a40"/></dir></dir><file name="Data.php" hash="1c57859446ccbe78bdd3cf14cace8f19"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="4a2fcabe901e2baae0eea97a08f05363"/><file name="config.xml" hash="3208477f6797fd73eaf2baf679fcfad9"/><file name="system.xml" hash="2b37ce38dd2ef8ed6fde97ebe503eac3"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Sitewards_B2BProfessional.xml" hash="023a28f2a21cd706dea246807465b99f"/></dir></target><target name="magelocale"><dir name="de_DE"><file name="Sitewards_B2BProfessional.csv" hash="6015eda25375bedb1b91182fbf61b2af"/></dir><dir name="en_US"><file name="Sitewards_B2BProfessional.csv" hash="44feec9f9e16dcc49cb2576c3244df4b"/></dir></target></contents>
28
  <compatible/>
29
  <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php><package><name>Netzarbeiter_CustomerActivation</name><channel>community</channel><min>0.3.0</min><max/></package><package><name>Sitewards_DeliveryDate</name><channel>community</channel><min>0.1.0</min><max/></package><package><name>Sitewards_QuickOrders</name><channel>community</channel><min>0.1.0</min><max/></package></required></dependencies>
30
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Sitewards_B2BProfessional</name>
4
+ <version>3.0.1</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.opensource.org/licenses/gpl-license.php">GPL</license>
7
  <channel>community</channel>
20
  &#xB7; Activation for specific product categories&#xD;
21
  &#xB7; Activation for specific customer groups&#xD;
22
  &#xB7; Optional require login to access store</description>
23
+ <notes>Fix an issue with simple products shown as "Out of stock" on product listings but showing "In Stock" on the product details page.</notes>
24
  <authors><author><name>Sitewards Magento Team</name><user>sitewards</user><email>magento@sitewards.com</email></author></authors>
25
+ <date>2014-08-22</date>
26
+ <time>08:34:56</time>
27
+ <contents><target name="magecommunity"><dir name="Sitewards"><dir name="B2BProfessional"><dir name="Docs"><file name="Sitewards B2B Professional_Deutsch V4.pdf" hash="69c5aabb9eba3cb4d060206f68bfffa9"/><file name="Sitewards B2B Professional_ENG_V4.pdf" hash="ec57137d81856521207e5014dfad133d"/></dir><dir name="Helper"><file name="Category.php" hash="72689cd7ea584379faf651d5dab7c351"/><file name="Core.php" hash="42335338c141593bc65b1e7913e4faf1"/><file name="Customer.php" hash="66f0f771c367e84181392f08efd693a4"/><file name="Data.php" hash="986044678c3628e854048d3e41c4e51e"/><file name="Redirects.php" hash="4b6d65cbf94a58b8b8b74eb480075fed"/></dir><dir name="Model"><file name="Observer.php" hash="8559f644f93147215ab8f8e5d45e5495"/><dir name="System"><dir name="Config"><dir name="Source"><file name="Category.php" hash="c45ee6c8eaaec42d239705b591c77919"/><file name="Page.php" hash="4527fdfc9bba40aa98dffc6db8fa5d3e"/></dir></dir></dir></dir><dir name="Test"><dir name="Helper"><dir name="Data"><dir name="fixtures"><file name="testIsExtensionActive.yaml" hash="1597dbaa9909bf2cd6cdc41188d79a40"/></dir></dir><file name="Data.php" hash="1c57859446ccbe78bdd3cf14cace8f19"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="4a2fcabe901e2baae0eea97a08f05363"/><file name="config.xml" hash="10444a352684588e2bbea4f3e5bc305e"/><file name="system.xml" hash="2b37ce38dd2ef8ed6fde97ebe503eac3"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Sitewards_B2BProfessional.xml" hash="023a28f2a21cd706dea246807465b99f"/></dir></target><target name="magelocale"><dir name="de_DE"><file name="Sitewards_B2BProfessional.csv" hash="6015eda25375bedb1b91182fbf61b2af"/></dir><dir name="en_US"><file name="Sitewards_B2BProfessional.csv" hash="44feec9f9e16dcc49cb2576c3244df4b"/></dir></target></contents>
28
  <compatible/>
29
  <dependencies><required><php><min>5.3.0</min><max>6.0.0</max></php><package><name>Netzarbeiter_CustomerActivation</name><channel>community</channel><min>0.3.0</min><max/></package><package><name>Sitewards_DeliveryDate</name><channel>community</channel><min>0.1.0</min><max/></package><package><name>Sitewards_QuickOrders</name><channel>community</channel><min>0.1.0</min><max/></package></required></dependencies>
30
  </package>