-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nigel lundsten
committed
Sep 28, 2012
0 parents
commit 7d4e333
Showing
5 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace SpeckRandomProducts; | ||
|
||
class Module | ||
{ | ||
public function getAutoloaderConfig() | ||
{ | ||
return array( | ||
'Zend\Loader\StandardAutoloader' => array( | ||
'namespaces' => array( | ||
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, | ||
), | ||
), | ||
); | ||
} | ||
|
||
public function getViewHelperConfig() | ||
{ | ||
return array( | ||
'factories' => array( | ||
'speckFeaturedProducts' => function ($sm) { | ||
$sm = $sm->getServiceLocator(); | ||
$helper = new View\Helper\Product; | ||
$helper->setTemplate('product'); | ||
$helper->setCallable(array($sm->get('SpeckRandomProductMapper'), 'getFeaturedProducts')); | ||
$helper->setProductService($sm->get('catalog_product_service')); | ||
return $helper; | ||
}, | ||
), | ||
); | ||
} | ||
|
||
public function getConfig() | ||
{ | ||
return array( | ||
'service_manager' => array( | ||
'invokables' => array( | ||
'SpeckRandomProductMapper'=> 'SpeckRandomProducts\Mapper\Product', | ||
), | ||
), | ||
'view_manager' => array( | ||
'template_path_stack' => array( | ||
__DIR__ . '/view' | ||
), | ||
), | ||
); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CREATE TABLE `featured_product` ( | ||
`product_id` int(11) NOT NULL, | ||
`website_id` int(11) NOT NULL | ||
) ENGINE=InnoDB |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace SpeckRandomProducts\Mapper; | ||
|
||
use Catalog\Mapper\Product as SpeckProductMapper; | ||
|
||
class Product extends SpeckProductMapper | ||
{ | ||
public function getFeaturedProducts($limit=null) | ||
{ | ||
$siteId = 1; | ||
$limit = ($limit ?: 6); | ||
$table = $this->getTableName(); | ||
$linker = 'featured_product'; | ||
$select = $this->getSelect($table) | ||
->join($linker, $table . '.product_id = ' . $linker . '.product_id') | ||
->where(array('website_id' => $siteId)) | ||
->limit($limit); | ||
return $this->selectMany($select); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
namespace SpeckRandomProducts\View\Helper; | ||
|
||
use Zend\View\Helper\HelperInterface; | ||
use Zend\View\Helper\AbstractHelper; | ||
|
||
class Product extends AbstractHelper | ||
{ | ||
protected $products; | ||
protected $template; | ||
protected $callable; | ||
protected $params=array(); | ||
protected $productService; | ||
|
||
public function __invoke($params=null) | ||
{ | ||
$params = ($params ?: $this->params); | ||
$products = call_user_func_array($this->callable, $this->params); | ||
|
||
$html = ''; | ||
foreach ($products as $product) { | ||
$product = $this->getProductService()->getFullProduct($product->getProductId()); | ||
$html .= $this->getView()->render($this->template, array('product' => $product)); | ||
} | ||
return $html; | ||
} | ||
|
||
/** | ||
* @return products | ||
*/ | ||
public function getProducts() | ||
{ | ||
return $this->products; | ||
} | ||
|
||
/** | ||
* @param $products | ||
* @return self | ||
*/ | ||
public function setProducts($products) | ||
{ | ||
$this->products = $products; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return template | ||
*/ | ||
public function getTemplate() | ||
{ | ||
return $this->template; | ||
} | ||
|
||
/** | ||
* @param $template | ||
* @return self | ||
*/ | ||
public function setTemplate($template) | ||
{ | ||
$this->template = $template; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return callable | ||
*/ | ||
public function getCallable() | ||
{ | ||
return $this->callable; | ||
} | ||
|
||
/** | ||
* @param $callable | ||
* @return self | ||
*/ | ||
public function setCallable($callable) | ||
{ | ||
$this->callable = $callable; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return productService | ||
*/ | ||
public function getProductService() | ||
{ | ||
return $this->productService; | ||
} | ||
|
||
/** | ||
* @param $productService | ||
* @return self | ||
*/ | ||
public function setProductService($productService) | ||
{ | ||
$this->productService = $productService; | ||
return $this; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?=$product; ?><br/> |