Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicWatts committed Oct 15, 2019
2 parents a9769e8 + 97caf4b commit e4ecf4e
Show file tree
Hide file tree
Showing 24 changed files with 738 additions and 2 deletions.
Empty file modified .travis.yml
100644 → 100755
Empty file.
Empty file modified Block/Link.php
100644 → 100755
Empty file.
Empty file modified Block/Navigation.php
100644 → 100755
Empty file.
Empty file modified Block/Navigation/State.php
100644 → 100755
Empty file.
Empty file modified Block/Product/ListProduct.php
100644 → 100755
Empty file.
270 changes: 270 additions & 0 deletions Block/Widget/Special.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
<?php

namespace Xigen\Special\Block\Widget;

/**
* Special Widget class
*/
class Special extends \Magento\Catalog\Block\Product\NewProduct implements \Magento\Widget\Block\BlockInterface
{
/**
* Default value whether show pager or not
*/
const DEFAULT_SHOW_PAGER = false;

/**
* Default value for products per page
*/
const DEFAULT_PRODUCTS_PER_PAGE = 5;

/**
* Name of request parameter for page number value
* @deprecated
*/
const PAGE_VAR_NAME = 'fp';

/**
* Instance of pager block
* @var \Magento\Catalog\Block\Product\Widget\Html\Pager
*/
protected $_pager;

/**
* @var \Magento\Framework\Serialize\Serializer\Json
*/
private $serializer;

/**
* Special constructor.
* @param \Magento\Catalog\Block\Product\Context $context
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
* @param \Magento\Catalog\Model\Product\Visibility $catalogProductVisibility
* @param \Magento\Framework\App\Http\Context $httpContext
* @param array $data
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
*/
public function __construct(
\Magento\Catalog\Block\Product\Context $context,
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
\Magento\Catalog\Model\Product\Visibility $catalogProductVisibility,
\Magento\Framework\App\Http\Context $httpContext,
array $data = [],
\Magento\Framework\Serialize\Serializer\Json $serializer = null
) {
parent::__construct(
$context,
$productCollectionFactory,
$catalogProductVisibility,
$httpContext,
$data
);
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Serialize\Serializer\Json::class);
}

/**
* Product collection initialize process
* @return \Magento\Catalog\Model\ResourceModel\Product\Collection|Object|\Magento\Framework\Data\Collection
*/
protected function _getProductCollection()
{
return $this->_getSpeciaProductsCollection();
}

/**
* Prepare collection for recent product list
* @return \Magento\Catalog\Model\ResourceModel\Product\Collection|Object|\Magento\Framework\Data\Collection
*/
protected function _getSpeciaProductsCollection()
{
/** @var $collection \Magento\Catalog\Model\ResourceModel\Product\Collection */
$collection = $this->_productCollectionFactory->create();
$collection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds());

$date = new \Zend_Date();

$collection = $this->_addProductAttributesAndPrices($collection)
->addStoreFilter()
->addAttributeToFilter(
'special_from_date',
[
'or' => [
0 => [
'date' => true,
'to' => $date->get('YYYY-MM-dd') . ' 23:59:59'
],
1 => [
'is' => new \Zend_Db_Expr('null')
],
]
],
'left'
)
->addAttributeToFilter(
'special_to_date',
[
'or' => [
0 => [
'date' => true,
'from' => $date->get('YYYY-MM-dd') . ' 00:00:00'
],
1 => [
'is' => new \Zend_Db_Expr('null')
],
]
],
'left'
)
->addAttributeToFilter('special_price', ['gt' => '0.1'])
->addAttributeToFilter('price', ['gt' => '0.1'])
->addAttributeToFilter('special_price', ['lt' => new \Zend_Db_Expr('at_price.value')])
->addAttributeToSort('created_at', 'desc')
->setPageSize($this->getPageSize())
->setCurPage($this->getCurrentPage());

return $collection;
}

/**
* Get number of current page based on query value
* @return int
*/
public function getCurrentPage()
{
return abs((int) $this->getRequest()->getParam($this->getData('page_var_name')));
}

/**
* Get key pieces for caching block content
* @return array
*/
public function getCacheKeyInfo()
{
return array_merge(
parent::getCacheKeyInfo(),
[
$this->getProductsPerPage(),
(int) $this->getRequest()->getParam($this->getData('page_var_name'), 1),
$this->serializer->serialize($this->getRequest()->getParams())
]
);
}

/**
* Retrieve how many products should be displayed
* @return int
*/
public function getProductsCount()
{
if (!$this->hasData('products_count')) {
return parent::getProductsCount();
}
return $this->getData('products_count');
}

/**
* Retrieve how many products should be displayed
* @return int
*/
public function getProductsPerPage()
{
if (!$this->hasData('products_per_page')) {
$this->setData('products_per_page', self::DEFAULT_PRODUCTS_PER_PAGE);
}
return $this->getData('products_per_page');
}

/**
* Return flag whether pager need to be shown or not
* @return bool
*/
public function showPager()
{
if (!$this->hasData('show_pager')) {
$this->setData('show_pager', self::DEFAULT_SHOW_PAGER);
}
return (bool) $this->getData('show_pager');
}

/**
* Retrieve how many products should be displayed on page
* @return int
*/
protected function getPageSize()
{
return $this->showPager() ? $this->getProductsPerPage() : $this->getProductsCount();
}

/**
* Render pagination HTML
* @return string
*/
public function getPagerHtml()
{
if ($this->showPager()) {
if (!$this->_pager) {
$this->_pager = $this->getLayout()->createBlock(
\Magento\Catalog\Block\Product\Widget\Html\Pager::class,
'widget.special.product.list.pager'
);

$this->_pager->setUseContainer(true)
->setShowAmounts(true)
->setShowPerPage(false)
->setPageVarName($this->getData('page_var_name'))
->setLimit($this->getProductsPerPage())
->setTotalLimit($this->getProductsCount())
->setCollection($this->getProductCollection());
}
if ($this->_pager instanceof \Magento\Framework\View\Element\AbstractBlock) {
return $this->_pager->toHtml();
}
}
return '';
}

/**
* Return HTML block with price
* @param \Magento\Catalog\Model\Product $product
* @param string $priceType
* @param string $renderZone
* @param array $arguments
* @return string
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function getProductPriceHtml(
\Magento\Catalog\Model\Product $product,
$priceType = null,
$renderZone = \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST,
array $arguments = []
) {
if (!isset($arguments['zone'])) {
$arguments['zone'] = $renderZone;
}
$arguments['zone'] = isset($arguments['zone'])
? $arguments['zone']
: $renderZone;
$arguments['price_id'] = isset($arguments['price_id'])
? $arguments['price_id']
: 'old-price-' . $product->getId() . '-' . $priceType;
$arguments['include_container'] = isset($arguments['include_container'])
? $arguments['include_container']
: true;
$arguments['display_minimal_price'] = isset($arguments['display_minimal_price'])
? $arguments['display_minimal_price']
: true;

/** @var \Magento\Framework\Pricing\Render $priceRender */
$priceRender = $this->getLayout()->getBlock('product.price.render.default');

$price = '';
if ($priceRender) {
$price = $priceRender->render(
\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE,
$product,
$arguments
);
}
return $price;
}
}
Empty file modified Controller/Index/Index.php
100644 → 100755
Empty file.
Empty file modified Model/Layer.php
100644 → 100755
Empty file.
Empty file modified Model/Layer/Resolver.php
100644 → 100755
Empty file.
Empty file modified Model/ResourceModel/Layer/Filter/Price.php
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion composer.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Special offers landing page with layered navigation",
"type": "magento2-module",
"license": "proprietary",
"version": "1.1.1",
"version": "1.1.2",
"authors": [
{
"name": "Dominic Xigen",
Expand Down
Empty file modified etc/di.xml
100644 → 100755
Empty file.
Empty file modified etc/frontend/routes.xml
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion etc/module.xml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Xigen_Special" setup_version="1.1.1">
<module name="Xigen_Special" setup_version="1.1.2">
</module>
</config>
66 changes: 66 additions & 0 deletions etc/widget.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" ?>
<widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Widget:etc/widget.xsd">
<widget class="Xigen\Special\Block\Widget\Special" id="xigen_special_special">
<label>Special Products List</label>
<description>List of products that are set as special Products</description>
<parameters>
<parameter name="show_pager" xsi:type="select" visible="true" source_model="Magento\Config\Model\Config\Source\Yesno">
<label translate="true">Display Page Control</label>
</parameter>
<parameter name="products_per_page" xsi:type="text" required="true" visible="true">
<label translate="true">Number of Products per Page</label>
<depends>
<parameter name="show_pager" value="1"/>
</depends>
<value>5</value>
</parameter>
<parameter name="products_count" xsi:type="text" required="true" visible="true">
<label translate="true">Number of Products to Display</label>
<value>10</value>
</parameter>
<parameter name="template" xsi:type="select" required="true" visible="true">
<label translate="true">Template</label>
<options>
<option name="default" value="product/widget/special/content/special_grid.phtml" selected="true">
<label translate="true">Special Products Grid Template</label>
</option>
<option name="list" value="product/widget/special/content/special_list.phtml">
<label translate="true">Special Products List Template</label>
</option>
<option name="list_default"
value="product/widget/special/column/special_default_list.phtml">
<label translate="true">Special Products Images and Names Template</label>
</option>
<option name="list_names"
value="product/widget/special/column/special_names_list.phtml">
<label translate="true">Special Products Names Only Template</label>
</option>
<option name="list_images"
value="product/widget/special/column/special_images_list.phtml">
<label translate="true">Special Products Images Only Template</label>
</option>
</options>
</parameter>
<parameter name="cache_lifetime" xsi:type="text" visible="true">
<label translate="true">Cache Lifetime (Seconds)</label>
<description translate="true">86400 by default, if not set. To refresh instantly, clear the Blocks HTML Output cache.</description>
</parameter>
</parameters>
<containers>
<container name="sidebar.main">
<template name="default" value="list_default"/>
<template name="names_only" value="list_names"/>
<template name="images_only" value="list_images"/>
</container>
<container name="content">
<template name="grid" value="default"/>
<template name="list" value="list"/>
</container>
<container name="sidebar.additional">
<template name="default" value="list_default"/>
<template name="names_only" value="list_names"/>
<template name="images_only" value="list_images"/>
</container>
</containers>
</widget>
</widgets>
Empty file modified registration.php
100644 → 100755
Empty file.
Empty file modified view/frontend/layout/default.xml
100644 → 100755
Empty file.
Empty file modified view/frontend/layout/special_index_index.xml
100644 → 100755
Empty file.
Loading

0 comments on commit e4ecf4e

Please sign in to comment.