Skip to content

Commit

Permalink
Merge pull request #6 from magmodules/cli
Browse files Browse the repository at this point in the history
1.2.5
  • Loading branch information
Marvin-Magmodules authored Dec 27, 2017
2 parents f53d24b + 9f04bd0 commit 506b625
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 12 deletions.
42 changes: 33 additions & 9 deletions app/code/community/Magmodules/Sooqr/Model/Sooqr.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public function generateFeed($storeId, $type = 'xml')
$products->setCurPage($curPage);
$products->load();

if ($config['reviews']) {
Mage::getModel('review/review')->appendSummary($products);
}

$parentRelations = $this->helper->getParentsFromCollection($products, $config);
$parents = $this->getParents($parentRelations, $config);
$prices = $this->helper->getTypePrices($config, $parents);
Expand Down Expand Up @@ -125,10 +129,8 @@ protected function setMemoryLimit($storeId)
public function getFeedConfig($storeId, $type = 'xml')
{
$config = array();

$store = Mage::app()->getStore($storeId);
$store = Mage::getModel('core/store')->load($storeId);
$website = Mage::getModel('core/website')->load($store->getWebsiteId());
$websiteUrl = $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);

$config['store_id'] = $storeId;
$config['website_name'] = $this->helper->cleanData($website->getName(), 'striptags');
Expand All @@ -142,11 +144,12 @@ public function getFeedConfig($storeId, $type = 'xml')
$config['image_resize'] = Mage::getStoreConfig('sooqr_connect/products/image_resize', $storeId);
$config['file_name'] = $this->getFileName('sooqr', $storeId);
$config['file_path'] = Mage::getBaseDir() . DS . 'media' . DS . 'sooqr';
$config['file_url'] = $websiteUrl . 'sooqr' . DS . $config['file_name'];
$config['file_url'] = $config['media_url'] . 'sooqr' . DS . $config['file_name'];
$config['version'] = (string)Mage::getConfig()->getNode()->modules->Magmodules_Sooqr->version;
$config['filter_enabled'] = Mage::getStoreConfig('sooqr_connect/products/category_enabled', $storeId);
$config['filter_cat'] = Mage::getStoreConfig('sooqr_connect/products/categories', $storeId);
$config['filter_type'] = Mage::getStoreConfig('sooqr_connect/products/category_type', $storeId);
$config['reviews'] = Mage::getStoreConfig('sooqr_connect/products/reviews');
$config['cms_pages'] = Mage::getStoreConfig('sooqr_connect/products/cms_pages', $storeId);
$config['cms_include'] = Mage::getStoreConfig('sooqr_connect/products/cms_include', $storeId);
$config['filters'] = @unserialize(Mage::getStoreConfig('sooqr_connect/products/advanced', $storeId));
Expand All @@ -163,10 +166,10 @@ public function getFeedConfig($storeId, $type = 'xml')
$config['simple_price'] = Mage::getStoreConfig('sooqr_connect/products/simple_price', $storeId);
$config['force_tax'] = Mage::getStoreConfig('sooqr_connect/products/force_tax', $storeId);
$config['price_rules'] = true;
$config['currency'] = Mage::app()->getStore($storeId)->getCurrentCurrencyCode();
$config['currency'] = $store->getCurrentCurrencyCode();
$config['currency_allow'] = Mage::getStoreConfig('currency/options/allow', $storeId);
$config['hide_currency'] = true;
$config['base_currency_code'] = Mage::app()->getStore($storeId)->getBaseCurrencyCode();
$config['base_currency_code'] = $store->getBaseCurrencyCode();
$config['currency_data'] = $this->getCurrencies($storeId, $config['base_currency_code'], $config['currency']);
$config['conf_enabled'] = Mage::getStoreConfig('sooqr_connect/products/conf_enabled', $storeId);
$config['conf_fields'] = Mage::getStoreConfig('sooqr_connect/products/conf_fields', $storeId);
Expand Down Expand Up @@ -425,6 +428,10 @@ public function getExtraDataFields($productData, $config, $product, $prices)
$extraDataFields = array_merge($extraDataFields, $stockData);
}

if ($reviewData = $this->getReviewData($config, $product)) {
$extraDataFields = array_merge($extraDataFields, $reviewData);
}

return $extraDataFields;
}

Expand Down Expand Up @@ -527,7 +534,7 @@ public function getAssocId($data)
$assocId['assoc_id'] = $data['id'];
}

if ($data['product_object_type'] != 'simple') {
if (isset($data['product_object_type']) && $data['product_object_type'] != 'simple') {
$assocId['is_parent'] = '1';
} else {
$assocId['is_parent'] = '0';
Expand Down Expand Up @@ -560,6 +567,22 @@ public function getStockData($config, $product)
return $stockData;
}

/**
* @param $config
* @param $product
*
* @return array
*/
public function getReviewData($config, $product)
{
$reviewData = array();
if ($config['reviews'] && $ratingSummary = $product->getRatingSummary()) {
$reviewData['rating'] = $ratingSummary->getRatingSummary();
}

return $reviewData;
}

/**
* @param $config
*
Expand Down Expand Up @@ -603,7 +626,8 @@ public function getInstallation()
$json['search']['enabled'] = '0';
$storeIds = Mage::helper('sooqr')->getStoreIds('sooqr_connect/generate/enabled');
foreach ($storeIds as $storeId) {
$mediaUrl = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
$store = Mage::getModel('core/store')->load($storeId);
$mediaUrl = $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
if (!$fileName = Mage::getStoreConfig('sooqr_connect/generate/filename', $storeId)) {
$fileName = 'soorq.xml';
}
Expand All @@ -614,7 +638,7 @@ public function getInstallation()
$fileName = substr($fileName, 0, -4) . '-' . $storeId . '.xml';
}

$name = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
$name = $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
$name = str_replace(array('https://', 'http://', 'www'), '', $name);

$json['feeds'][$storeId]['name'] = $name;
Expand Down
2 changes: 1 addition & 1 deletion app/code/community/Magmodules/Sooqr/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<config>
<modules>
<Magmodules_Sooqr>
<version>1.2.4</version>
<version>1.2.5</version>
</Magmodules_Sooqr>
</modules>
<global>
Expand Down
25 changes: 25 additions & 0 deletions app/code/community/Magmodules/Sooqr/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,31 @@
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</extra>
<reviews_heading translate="label">
<label>Product Reviews</label>
<frontend_model>sooqr/adminhtml_system_config_form_field_heading</frontend_model>
<sort_order>33</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</reviews_heading>
<reviews_note translate="label">
<label><![CDATA[Export the product rating score in the feed to use it in Sooqr Search. Please keep in mind that activating this option can cause a higher load on the feed generation.]]></label>
<frontend_model>sooqr/adminhtml_system_config_form_field_note</frontend_model>
<sort_order>34</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</reviews_note>
<reviews>
<label>Add Product Review Score</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>35</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</reviews>
<tax_heading translate="label">
<label>Prices and Tax</label>
<frontend_model>sooqr/adminhtml_system_config_form_field_heading</frontend_model>
Expand Down
1 change: 1 addition & 0 deletions app/locale/en_US/Magmodules_Sooqr.csv
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"Exclude for Sooqr","Exclude for Sooqr"
"Extension Version","Extension Version"
"Extention needs to be enabled to use this function","Extension needs to be enabled to use this function"
"Export the product rating score in the feed to use it in Sooqr Search. Please keep in mind that activating this option can cause a higher load on the feed generation.","Export the product rating score in the feed to use it in Sooqr Search. Please keep in mind that activating this option can cause a higher load on the feed generation."
"Feed Generation","Feed Generation"
"Feed Generation Settings","Feed Generation Settings"
"File writing not succeeded","File writing not succeeded"
Expand Down
2 changes: 2 additions & 0 deletions app/locale/nl_NL/Magmodules_Sooqr.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"Add your custom attributes as Sooqr fields. The maximum number of allowed fields is restricted by your Sooqr subscription.","Voeg handmatig extra attributen toe aan je Sooqr feed. Het maximaal aantal velden is afhankelijk van je soort Sooqr account."
"API Details","API gegevens"
"Advanced Settings","Geavanceerde Instellingen"
"Add Product Review Score","Product beoordelingscore toevoegen"
"Attribute","Attribuut"
"By default prices are shown incl. Tax so only change this option if necessary.<br>If the feed export is without tax it's possible to add it with this option.<br>","Standaard worden de prijzen incl. btw getoond, verander deze optie enkel als het nodig is.<br>Wanneer de export feed de prijzen toont exclusief BTW is het mogelijk deze optie te gebruiken.<br>"
"Cron","Cron"
Expand Down Expand Up @@ -35,6 +36,7 @@
"Exclude out of stock products","Producten welke niet op voorraad zijn uitsluiten"
"Exclude products with this visibility","Sluit producten met deze zichtbaarheid uit"
"Exclude for Sooqr","Uitsluiten voor Sooqr"
"Export the product rating score in the feed to use it in Sooqr Search. Please keep in mind that activating this option can cause a higher load on the feed generation.","Exporteer de product beoordeling score in de feed om deze te gebruiken in Sooqr Search. Houd er rekening mee dat het inschakelen van deze optie een hogere load kan veroorzaken tijdens het genereren van de feed."
"Extension Version","Extensie Versie"
"Extention needs to be enabled to use this function","De extensie dient geactiveerd te zijn om deze functie te gebruiken"
"Feed Generation","Feed Generatie"
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "magmodules/magento1-sooqr",
"type": "magento-module",
"description": "Magento 1 Sooqr integration",
"version": "v1.2.4",
"version": "v1.2.5",
"keywords": [
"magento","sooqr","search"
],
Expand Down
3 changes: 2 additions & 1 deletion modman
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ app/etc/modules/Magmodules_Sooqr.xml app/etc/modules/Magmodules_Sooqr
app/locale/en_US/Magmodules_Sooqr.csv app/locale/en_US/Magmodules_Sooqr.csv
app/locale/nl_NL/Magmodules_Sooqr.csv app/locale/nl_NL/Magmodules_Sooqr.csv
app/design/frontend/base/default/layout/magmodules_sooqr.xml app/design/frontend/base/default/layout/magmodules_sooqr.xml
app/design/frontend/base/default/template/magmodules/sooqr/form.mini.phtml app/design/frontend/base/default/template/magmodules/sooqr/form.mini.phtml
app/design/frontend/base/default/template/magmodules/sooqr/form.mini.phtml app/design/frontend/base/default/template/magmodules/sooqr/form.mini.phtml
shell/sooqr.php shell/sooqr.php
123 changes: 123 additions & 0 deletions shell/sooqr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php
/**
* Magmodules.eu - http://www.magmodules.eu
*
* NOTICE OF LICENSE
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @category Magmodules
* @package Magmodules_Sooqr
* @author Magmodules <[email protected]>
* @copyright Copyright (c) 2017 (http://www.magmodules.eu)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

require_once 'abstract.php';

class Sooqr_Shell_GenerateFeed extends Mage_Shell_Abstract
{

const XPATH_ENABLED = 'sooqr_connect/generate/enabled';
const XPATH_RESULT = 'sooqr_connect/generate/feed_result';

/**
*
*/
public function run()
{
if ($generate = $this->getArg('generate')) {
$storeIds = $this->getStoreIds($generate);
foreach ($storeIds as $storeId) {
$timeStart = microtime(true);
$feed = Mage::getModel('sooqr/sooqr')->generateFeed($storeId, 'cli');
echo $this->getResults($storeId, $feed, $timeStart) . PHP_EOL;
}
} else {
echo $this->usageHelp();
}
}

/**
* Returns all available storeIds for feed generation.
*
* @param $generate
*
* @return array
*/
public function getStoreIds($generate)
{
$allStores = Mage::helper('sooqr')->getStoreIds(self::XPATH_ENABLED);
if ($generate == 'next') {
$nextStore = Mage::helper('sooqr')->getUncachedConfigValue('sooqr_connect/generate/cron_next');
if (empty($nextStore) || ($nextStore >= count($allStores))) {
$nextStore = 0;
}
Mage::getModel('core/config')->saveConfig('sooqr_connect/generate/cron_next', ($nextStore + 1), 'default', 0);
return array($allStores[$nextStore]);
}

if ($generate == 'all') {
return $allStores;
}

return explode(',', trim($generate));
}

/**
* Parse and saves result.
*
* @param $storeId
* @param $result
* @param $timeStart
*
* @return string
*/
public function getResults($storeId, $result, $timeStart)
{
if (!empty($result)) {
$html = sprintf(
'<a href="%s" target="_blank">%s</a><br/><small>On: %s (cli) - Products: %s/%s - Time: %s</small>',
$result['url'],
$result['url'],
$result['date'],
$result['qty'],
$result['pages'],
Mage::helper('sooqr')->getTimeUsage($timeStart)
);
Mage::getModel('core/config')->saveConfig(self::XPATH_RESULT, $html, 'stores', $storeId);

return sprintf(
'Generated %s - Products: %s/%s - Time: %s',
$result['url'],
$result['qty'],
$result['pages'],
Mage::helper('sooqr')->getTimeUsage($timeStart)
);
} else {
return 'No feed found, please check storeId or is module is enabled';
}
}

/**
* Retrieve Usage Help Message.
*/
public function usageHelp()
{
return <<<USAGE
Usage: php -f sooqr.php -- [options]
--generate all Generate all stores
--generate next Generate next available store
--generate <id> Generate store <id> (comma seperated supported)
USAGE;
}

}

$shell = new Sooqr_Shell_GenerateFeed();
$shell->run();

0 comments on commit 506b625

Please sign in to comment.