From 6fa0683d5c143fed005deb93203cd7907802ee4e Mon Sep 17 00:00:00 2001 From: Andreas von Studnitz Date: Mon, 10 Jul 2017 17:28:37 +0200 Subject: [PATCH 1/4] 6505 Show products which are out of stock depending on the configuration for search results and autosuggest results --- composer.json | 2 +- .../IntegerNet/Solr/Model/Bridge/Product.php | 36 ++++++++++++------- .../IntegerNet/Solr/Model/Config/Store.php | 5 +-- .../community/IntegerNet/Solr/etc/config.xml | 4 ++- .../community/IntegerNet/Solr/etc/system.xml | 19 ++++++++++ .../upgrade-1.7.3-1.7.4.php | 24 +++++++++++++ src/app/locale/de_DE/IntegerNet_Solr.csv | 5 ++- 7 files changed, 77 insertions(+), 18 deletions(-) create mode 100644 src/app/code/community/IntegerNet/Solr/sql/integernet_solr_setup/upgrade-1.7.3-1.7.4.php diff --git a/composer.json b/composer.json index a450855..8634482 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "homepage": "https://github.com/integer-net/solr-magento1", "require": { "aoepeople/aoe_layoutconditions": "~1.0.0", - "integer-net/solr-base": "~2.0.0" + "integer-net/solr-base": "~3.0.0" }, "require-dev": { "ecomdev/ecomdev_phpunit": "dev-dev", diff --git a/src/app/code/community/IntegerNet/Solr/Model/Bridge/Product.php b/src/app/code/community/IntegerNet/Solr/Model/Bridge/Product.php index 6155d6a..b065c87 100644 --- a/src/app/code/community/IntegerNet/Solr/Model/Bridge/Product.php +++ b/src/app/code/community/IntegerNet/Solr/Model/Bridge/Product.php @@ -65,7 +65,14 @@ public function hasSpecialPrice() public function getSolrBoost() { - return $this->_product->getData('solr_boost'); + $boost = $this->_product->getData('solr_boost'); + if (!$this->isInStock()) { + if ($boost === null) { + $boost = 1; + } + $boost *= floatval(Mage::getStoreConfig('integernet_solr/results/priority_outofstock')); + } + return $boost; } public function getPrice() @@ -133,18 +140,6 @@ public function isIndexable() if (!in_array($this->_product->getStore()->getWebsiteId(), $this->_product->getWebsiteIds())) { return false; } - if (!Mage::helper('cataloginventory')->isShowOutOfStock()) { - /** @var Mage_CatalogInventory_Model_Stock_Item $stockItem */ - if (!$this->_product->getStockItem()) { - $stockItem = Mage::getModel('cataloginventory/stock_item') - ->loadByProduct($this->_product->getId()); - $this->_product->setStockItem($stockItem); - } - - if (!$this->_product->getStockItem()->getIsInStock()) { - return false; - } - } return true; } @@ -159,4 +154,19 @@ public function __call($method, $args) { return call_user_func_array(array($this->_product, $method), $args); } + + /** + * return boolean + */ + public function isInStock() + { + /** @var Mage_CatalogInventory_Model_Stock_Item $stockItem */ + if (!$this->_product->getStockItem()) { + $stockItem = Mage::getModel('cataloginventory/stock_item') + ->loadByProduct($this->_product->getId()); + $this->_product->setStockItem($stockItem); + } + + return $this->_product->getStockItem()->getIsInStock(); + } } \ No newline at end of file diff --git a/src/app/code/community/IntegerNet/Solr/Model/Config/Store.php b/src/app/code/community/IntegerNet/Solr/Model/Config/Store.php index 4c25002..457da29 100644 --- a/src/app/code/community/IntegerNet/Solr/Model/Config/Store.php +++ b/src/app/code/community/IntegerNet/Solr/Model/Config/Store.php @@ -163,7 +163,8 @@ public function getAutosuggestConfig() $this->_getConfig($prefix . 'max_number_cms_page_suggestions'), $this->_getConfigFlag($prefix . 'show_complete_category_path'), $this->_getConfig($prefix . 'category_link_type'), - @unserialize($this->_getConfig($prefix . 'attribute_filter_suggestions')) + @unserialize($this->_getConfig($prefix . 'attribute_filter_suggestions')), + $this->_getConfig($prefix . 'show_outofstock') ); } return $this->_autosuggest; @@ -222,7 +223,7 @@ public function getResultsConfig() $this->_getConfig($prefix . 'max_price'), $this->_getConfigFlag($prefix . 'use_custom_price_intervals'), explode(',', $this->_getConfig($prefix . 'custom_price_intervals')), - $this->_getConfigFlag($prefix . 'show_category_filter') + $this->_getConfig($prefix . 'show_outofstock') ); } return $this->_results; diff --git a/src/app/code/community/IntegerNet/Solr/etc/config.xml b/src/app/code/community/IntegerNet/Solr/etc/config.xml index c1dff63..3570cb3 100644 --- a/src/app/code/community/IntegerNet/Solr/etc/config.xml +++ b/src/app/code/community/IntegerNet/Solr/etc/config.xml @@ -2,7 +2,7 @@ - 1.7.3 + 1.7.4 @@ -257,6 +257,8 @@ 1 1 2 + 1 + 1 0 10 200 diff --git a/src/app/code/community/IntegerNet/Solr/etc/system.xml b/src/app/code/community/IntegerNet/Solr/etc/system.xml index c2b751f..df5344f 100644 --- a/src/app/code/community/IntegerNet/Solr/etc/system.xml +++ b/src/app/code/community/IntegerNet/Solr/etc/system.xml @@ -309,6 +309,25 @@ 1 1 + + + select + adminhtml/system_config_source_yesno + 57 + 1 + 1 + 1 + + + + 0 = don't show at all, 1 = don't modify, anything between = lower priority + text + validate-number validate-zero-or-greater + 58 + 1 + 1 + 1 + diff --git a/src/app/code/community/IntegerNet/Solr/sql/integernet_solr_setup/upgrade-1.7.3-1.7.4.php b/src/app/code/community/IntegerNet/Solr/sql/integernet_solr_setup/upgrade-1.7.3-1.7.4.php new file mode 100644 index 0000000..4e87c1e --- /dev/null +++ b/src/app/code/community/IntegerNet/Solr/sql/integernet_solr_setup/upgrade-1.7.3-1.7.4.php @@ -0,0 +1,24 @@ + + */ + +/** @var Mage_Catalog_Model_Resource_Setup $installer */ +$installer = $this; + +$installer->startSetup(); + +$installer->setConfigData('integernet_solr/results/show_outofstock', Mage::getStoreConfig('cataloginventory/options/show_out_of_stock')); +$installer->setConfigData('integernet_solr/autosuggest/show_outofstock', Mage::getStoreConfig('cataloginventory/options/show_out_of_stock')); + +Mage::getModel('index/process') + ->load('integernet_solr', 'indexer_code') + ->setStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX) + ->save(); + +$installer->endSetup(); \ No newline at end of file diff --git a/src/app/locale/de_DE/IntegerNet_Solr.csv b/src/app/locale/de_DE/IntegerNet_Solr.csv index 62720f1..f7a3193 100644 --- a/src/app/locale/de_DE/IntegerNet_Solr.csv +++ b/src/app/locale/de_DE/IntegerNet_Solr.csv @@ -106,4 +106,7 @@ "0 = all","0 = alle" "Sort Filter Options alphabetically","Filteroptionen alphabetisch sortieren" "By default, filters are sorted by number of results.","Filter sind standardmäßig nach Anzahl der Treffer sortiert." -"Show category filter","Kategorie-Filter anzeigen" \ No newline at end of file +"Show category filter","Kategorie-Filter anzeigen" +"Show products which are out of stock","Produkte anzeigen, die nicht auf Lager sind" +"Solr Priority Multiplier for Products being out of Stock","Solr-Prioritäts-Multiplikator für ausverkaufte Produkte" +"0 = don't show at all, 1 = don't modify, anything between = lower priority","0 = gar nicht anzeigen, 1 = wie Produkte auf Lager, alles dazwischen = niedrigere Priorität" \ No newline at end of file From 7a5b788c06abd2da20496455e93f2991c735eac1 Mon Sep 17 00:00:00 2001 From: Andreas von Studnitz Date: Mon, 10 Jul 2017 17:49:29 +0200 Subject: [PATCH 2/4] 6505 Show products which are out of stock depending on the configuration for category pages --- src/app/code/community/IntegerNet/Solr/Helper/Factory.php | 2 ++ src/app/code/community/IntegerNet/Solr/Model/Config/Store.php | 3 ++- .../Solr/sql/integernet_solr_setup/upgrade-1.7.3-1.7.4.php | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/app/code/community/IntegerNet/Solr/Helper/Factory.php b/src/app/code/community/IntegerNet/Solr/Helper/Factory.php index 3eb708d..bb0cd9e 100644 --- a/src/app/code/community/IntegerNet/Solr/Helper/Factory.php +++ b/src/app/code/community/IntegerNet/Solr/Helper/Factory.php @@ -101,6 +101,8 @@ public function getSolrRequest($requestMode = self::REQUEST_MODE_AUTODETECT) $this->getSolrResource(), $storeId); } elseif ($isCategoryPage) { + $applicationContext + ->setCategoryConfig($this->getCurrentStoreConfig()->getCategoryConfig()); $factory = new CategoryRequestFactory( $applicationContext, $this->getSolrResource(), diff --git a/src/app/code/community/IntegerNet/Solr/Model/Config/Store.php b/src/app/code/community/IntegerNet/Solr/Model/Config/Store.php index 457da29..31a78e6 100644 --- a/src/app/code/community/IntegerNet/Solr/Model/Config/Store.php +++ b/src/app/code/community/IntegerNet/Solr/Model/Config/Store.php @@ -265,7 +265,8 @@ public function getCategoryConfig() $this->_getConfigFlag($prefix . 'use_in_search_results'), intval($this->_getConfig($prefix . 'max_number_results')), $this->_getConfigFlag($prefix . 'fuzzy_is_active'), - floatval($this->_getConfig($prefix . 'fuzzy_sensitivity')) + floatval($this->_getConfig($prefix . 'fuzzy_sensitivity')), + $this->_getConfig($prefix . 'show_outofstock') ); } return $this->_category; diff --git a/src/app/code/community/IntegerNet/Solr/sql/integernet_solr_setup/upgrade-1.7.3-1.7.4.php b/src/app/code/community/IntegerNet/Solr/sql/integernet_solr_setup/upgrade-1.7.3-1.7.4.php index 4e87c1e..16107ea 100644 --- a/src/app/code/community/IntegerNet/Solr/sql/integernet_solr_setup/upgrade-1.7.3-1.7.4.php +++ b/src/app/code/community/IntegerNet/Solr/sql/integernet_solr_setup/upgrade-1.7.3-1.7.4.php @@ -15,6 +15,7 @@ $installer->setConfigData('integernet_solr/results/show_outofstock', Mage::getStoreConfig('cataloginventory/options/show_out_of_stock')); $installer->setConfigData('integernet_solr/autosuggest/show_outofstock', Mage::getStoreConfig('cataloginventory/options/show_out_of_stock')); +$installer->setConfigData('integernet_solr/category/show_outofstock', Mage::getStoreConfig('cataloginventory/options/show_out_of_stock')); Mage::getModel('index/process') ->load('integernet_solr', 'indexer_code') From abd0cc89dc709f2c62f899e939ecac706d7240b3 Mon Sep 17 00:00:00 2001 From: Andreas von Studnitz Date: Tue, 11 Jul 2017 09:45:12 +0200 Subject: [PATCH 3/4] 6505 Adjust composer dependencies before the release --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8634482..32888c5 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "homepage": "https://github.com/integer-net/solr-magento1", "require": { "aoepeople/aoe_layoutconditions": "~1.0.0", - "integer-net/solr-base": "~3.0.0" + "integer-net/solr-base": "dev-solr-priority-for-outofstock-products" }, "require-dev": { "ecomdev/ecomdev_phpunit": "dev-dev", From da4dd3ad5b38949d248ad6eea3b2123a37a36159 Mon Sep 17 00:00:00 2001 From: Andreas von Studnitz Date: Tue, 11 Jul 2017 14:14:36 +0200 Subject: [PATCH 4/4] 6505 Update Integration Tests --- src/app/code/community/IntegerNet/Solr/Test/Model/Result.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/code/community/IntegerNet/Solr/Test/Model/Result.php b/src/app/code/community/IntegerNet/Solr/Test/Model/Result.php index f40b20d..5f7491a 100644 --- a/src/app/code/community/IntegerNet/Solr/Test/Model/Result.php +++ b/src/app/code/community/IntegerNet/Solr/Test/Model/Result.php @@ -95,7 +95,7 @@ public function shouldUseParametersBasedOnToolbar() ) ); $logMock->expects($this->at(4))->method('debug')->with( - 'Filter Query: content_type:product AND store_id:1 AND is_visible_in_search_i:1'); + 'Filter Query: content_type:product AND store_id:1 AND is_visible_in_search_i:1 AND -is_in_stock_i:0'); /* @var Mage_Core_Block_Text $toolbar Not using actual toolbar block which reads from session */ $toolbar = $this->app()->getLayout()->createBlock('core/text', 'product_list_toolbar');