Created
April 12, 2013 05:30
-
-
Save sthamann/5369647 to your computer and use it in GitHub Desktop.
Modification of community store plugin SwagCustomCategories
to allow more then one condition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin-Controller to display the special article-groups in the frontend | |
* | |
* @link http://www.shopware.de | |
* @copyright Copyright (c) 2011, shopware AG | |
* @author Patrick Stahl | |
* @package Plugins | |
* @subpackage Frontend_Controller | |
*/ | |
class Shopware_Controllers_Frontend_SwagCustomCategories extends Enlight_Controller_Action | |
{ | |
protected $_debug = false; | |
protected $_maxArticles = 12; | |
/** | |
* Adds the default template directory 'Views' to use the new templates | |
* @return void | |
*/ | |
public function init() | |
{ | |
if ($this->_debug == false){ | |
$this->View()->addTemplateDir(dirname(__FILE__) . "../../Views/"); | |
$this->_maxArticles = Shopware()->Plugins()->Frontend()->SwagCustomCategories()->Config()->maxArticles; | |
} | |
} | |
/** | |
* Function to create the whole listing by the given parameter | |
* | |
* @return void | |
*/ | |
public function indexAction() | |
{ | |
if (!$this->_debug){ | |
$this->View()->loadTemplate("frontend/plugins/swag_custom_categories/index.tpl"); | |
}else { | |
$this->View()->setTemplate(); | |
} | |
// Check which articles shall be shown | |
switch($this->Request()->filterMode) { | |
case 'newest': | |
$maxArticles = $this->_maxArticles; | |
$sql="SELECT id | |
FROM `s_articles` | |
WHERE IF(DATEDIFF(NOW(), datum)<=60,1,0)>0 | |
ORDER BY datum DESC"; | |
$results = Shopware()->Db()->fetchCol($sql, array()); | |
$articles = array(); | |
foreach($results as $result) { | |
$article = Shopware()->Modules()->Articles()->sGetPromotionById('fix', 0, $result); | |
if(!empty($article)) { | |
$articles[] = $article; | |
} | |
if(count($articles) == $maxArticles) { | |
break; | |
} | |
} | |
$this->View()->sArticles = $articles; | |
break; | |
case 'pseudo': | |
$maxArticles = $this->_maxArticles; | |
$sql = "SELECT articleID | |
FROM s_articles_prices | |
WHERE pseudoprice > 0 | |
GROUP BY articleID | |
ORDER BY id DESC"; | |
$results = Shopware()->Db()->fetchCol($sql); | |
$articles = array(); | |
foreach($results as $result) { | |
$article = Shopware()->Modules()->Articles()->sGetPromotionById('fix', 0, $result); | |
if(!empty($article)) { | |
$articles[] = $article; | |
} | |
if(count($articles) == $maxArticles) { | |
break; | |
} | |
} | |
$this->View()->sArticles = $articles; | |
break; | |
default: | |
$maxArticles = $this->_maxArticles; | |
$attr = $this->Request()->filterMode; | |
if(strpos($attr, "attr") !== false) { | |
$attr = explode("|",$attr); | |
$content = explode("|",$this->Request()->content); | |
$sqlAdd = ""; | |
foreach ($attr as $attributKey => $attributKV){ | |
$attributKV = Shopware()->Db()->quoteIdentifier($attributKV); | |
if (!empty($content[$attributKey])){ | |
$condition = " | |
\nNULLIF({$attributKV},'') IS NOT NULL | |
\nAND {$attributKV} = ".Shopware()->Db()->quote($content[$attributKey]); | |
}else { | |
$condition = " | |
\nNULLIF({$attributKV},'') IS NOT NULL | |
\nAND {$attributKV} <> '0'"; | |
} | |
$sqlAdd[] = $condition; | |
} | |
$sql="SELECT articleID FROM `s_articles_attributes` WHERE ".implode($sqlAdd," AND ")." ORDER BY id DESC "; | |
$results = Shopware()->Db()->fetchCol($sql, array()); | |
$articles = array(); | |
foreach($results as $result) { | |
$article = Shopware()->Modules()->Articles()->sGetPromotionById('fix', 0, $result); | |
if(!empty($article)) { | |
$articles[] = $article; | |
} | |
if(count($articles) == $maxArticles) { | |
break; | |
} | |
} | |
} | |
$this->View()->sArticles = $articles; | |
break; | |
} | |
if ($this->_debug){ | |
print_r($articles);exit; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment