Created
December 19, 2018 20:10
-
-
Save bigin/f24406772ef68737fd7651d2b42bda96 to your computer and use it in GitHub Desktop.
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 | |
register_plugin( | |
basename(__FILE__, '.php'), | |
'SimpleCatalog Extender', | |
'0.1', | |
'Your name', | |
'your website url', | |
'A SimpleCatalog extension', | |
'', | |
'' | |
); | |
add_action('imcatalog', 'action'); | |
function action() | |
{ | |
class ExtendedController extends \ImCatalog\Controller | |
{ | |
public function renderSection($sectionName, $params = array()) | |
{ | |
if($sectionName == 'FrontendItemDetails') { | |
$this->renderFrontendItemDetails(); | |
} else { | |
return parent::renderSection($sectionName, $params); | |
} | |
} | |
/** | |
* There is your extended method | |
*/ | |
private function renderFrontendItemDetails() | |
{ | |
$currentItem = $this->processor->getItem($this->router->currentRoute['categoryid'], $this->router->currentRoute['id']); | |
if($currentItem && $currentItem->active != 1) $currentItem = null; | |
$itemDetailsContent = $this->getTemplate($currentItem); | |
if(empty($currentItem)) { | |
$this->content = $this->parser->render($itemDetailsContent, array( | |
'description' => Util::i18n_r('err_item_not_found') | |
) | |
); | |
return; | |
} | |
$output = $itemDetailsContent; | |
foreach($currentItem as $key => $value) | |
{ | |
if(is_array($value)) continue; | |
$output = $this->parser->render($output, array($key => $value)); | |
} | |
$this->content = $output; | |
} | |
private function getTemplate($currentItem) { | |
ob_start(); ?> | |
<div class="sc-element-wrapper"> | |
<?php | |
$output = ''; | |
if(!empty($currentItem->image)) | |
{ | |
$path_r = ''; | |
$path = ''; | |
foreach($currentItem->image as $key => $image) | |
{ | |
if($this->processor->config->itemDetailsImageResize) | |
{ | |
$path_r = \ImCatalog\Util::getResizedUrl($currentItem, | |
$key, | |
$this->processor->config->itemDetailsImageSizes[$key]['w'], | |
$this->processor->config->itemDetailsImageSizes[$key]['h'], | |
'resize' | |
); | |
} | |
$title = isset($currentItem->image_title[$key]) ? $currentItem->image_title[$key] : ''; | |
$output .= '<figure>'. | |
' <img src="'.$path_r.'" alt="'.$title.'">'. | |
'</figure>'; | |
} | |
} | |
echo $output | |
?> | |
<div class="sc-element-details"> | |
[[description]] | |
</div> | |
</div> | |
<?php return ob_get_clean(); | |
} | |
} | |
$catalog = new ExtendedController(); | |
\ImCatalog\Factory::buildCatalog($catalog); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment