Skip to content

Solr priority for outofstock products #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "dev-solr-priority-for-outofstock-products"
},
"require-dev": {
"ecomdev/ecomdev_phpunit": "dev-dev",
Expand Down
2 changes: 2 additions & 0 deletions src/app/code/community/IntegerNet/Solr/Helper/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
36 changes: 23 additions & 13 deletions src/app/code/community/IntegerNet/Solr/Model/Bridge/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;

}
Expand All @@ -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();
}
}
8 changes: 5 additions & 3 deletions src/app/code/community/IntegerNet/Solr/Model/Config/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -264,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 3 additions & 1 deletion src/app/code/community/IntegerNet/Solr/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<config>
<modules>
<IntegerNet_Solr>
<version>1.7.3</version>
<version>1.7.4</version>
<version_suffix />
</IntegerNet_Solr>
</modules>
Expand Down Expand Up @@ -257,6 +257,8 @@
<filter_position>1</filter_position>
<show_category_filter>1</show_category_filter>
<priority_categories>2</priority_categories>
<show_outofstock>1</show_outofstock>
<priority_outofstock>1</priority_outofstock>
<max_number_filter_options>0</max_number_filter_options>
<price_step_size>10</price_step_size>
<max_price>200</max_price>
Expand Down
19 changes: 19 additions & 0 deletions src/app/code/community/IntegerNet/Solr/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,25 @@
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</priority_categories>
<show_outofstock translate="label,comment">
<label>Show products which are out of stock</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>57</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</show_outofstock>
<priority_outofstock translate="label,comment">
<label>Solr Priority Multiplier for Products being out of Stock</label>
<comment>0 = don't show at all, 1 = don't modify, anything between = lower priority</comment>
<frontend_type>text</frontend_type>
<validate>validate-number validate-zero-or-greater</validate>
<sort_order>58</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</priority_outofstock>
<price_step_size translate="label,comment">
<label>Size of Price Steps</label>
<comment><![CDATA[i.e. 100]]></comment>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* integer_net Magento Module
*
* @category IntegerNet
* @package IntegerNet_Solr
* @copyright Copyright (c) 2016 integer_net GmbH (http://www.integer-net.de/)
* @author Andreas von Studnitz <avs@integer-net.de>
*/

/** @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'));
$installer->setConfigData('integernet_solr/category/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();
5 changes: 4 additions & 1 deletion src/app/locale/de_DE/IntegerNet_Solr.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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"
"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"