Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
NewWidget Class Reference
Inheritance diagram for NewWidget:
NewProduct BlockInterface AbstractProduct IdentityInterface Template AbstractBlock DataObject BlockInterface

Public Member Functions

 __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)
 
 getCurrentPage ()
 
 getCacheKeyInfo ()
 
 getDisplayType ()
 
 getProductsCount ()
 
 getProductsPerPage ()
 
 showPager ()
 
 getPagerHtml ()
 
- Public Member Functions inherited from NewProduct
 __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=[])
 
 getCacheKeyInfo ()
 
 setProductsCount ($count)
 
 getProductsCount ()
 
 getIdentities ()
 
- Public Member Functions inherited from AbstractProduct
 __construct (\Magento\Catalog\Block\Product\Context $context, array $data=[])
 
 getAddToCartUrl ($product, $additional=[])
 
 getSubmitUrl ($product, $additional=[])
 
 getAddToWishlistParams ($product)
 
 getAddToCompareUrl ()
 
 getMinimalQty ($product)
 
 getReviewsSummaryHtml (\Magento\Catalog\Model\Product $product, $templateType=false, $displayIfNoReviews=false)
 
 getProduct ()
 
 getProductUrl ($product, $additional=[])
 
 hasProductUrl ($product)
 
 getColumnCount ()
 
 addColumnCountLayoutDepend ($pageLayout, $columnCount)
 
 removeColumnCountLayoutDepend ($pageLayout)
 
 getColumnCountLayoutDepend ($pageLayout)
 
 getPageLayout ()
 
 getCanShowProductPrice ($product)
 
 displayProductStockStatus ()
 
 getRandomString ($length, $chars=null)
 
 getProductPrice (\Magento\Catalog\Model\Product $product)
 
 isRedirectToCartEnabled ()
 
 getProductDetailsHtml (\Magento\Catalog\Model\Product $product)
 
 getDetailsRenderer ($type=null)
 
 getImage ($product, $imageId, $attributes=[])
 
- Public Member Functions inherited from Template
 __construct (Template\Context $context, array $data=[])
 
 setTemplateContext ($templateContext)
 
 getTemplate ()
 
 setTemplate ($template)
 
 getTemplateFile ($template=null)
 
 getArea ()
 
 assign ($key, $value=null)
 
 fetchView ($fileName)
 
 getBaseUrl ()
 
 getObjectData (\Magento\Framework\DataObject $object, $key)
 
 getCacheKeyInfo ()
 
- Public Member Functions inherited from AbstractBlock
 __construct (\Magento\Framework\View\Element\Context $context, array $data=[])
 
 getJsLayout ()
 
 getRequest ()
 
 getParentBlock ()
 
 setLayout (\Magento\Framework\View\LayoutInterface $layout)
 
 getLayout ()
 
 setNameInLayout ($name)
 
 getChildNames ()
 
 setAttribute ($name, $value=null)
 
 setChild ($alias, $block)
 
 addChild ($alias, $block, $data=[])
 
 unsetChild ($alias)
 
 unsetCallChild ($alias, $callback, $result, $params)
 
 unsetChildren ()
 
 getChildBlock ($alias)
 
 getChildHtml ($alias='', $useCache=true)
 
 getChildChildHtml ($alias, $childChildAlias='', $useCache=true)
 
 getBlockHtml ($name)
 
 insert ($element, $siblingName=0, $after=true, $alias='')
 
 append ($element, $alias='')
 
 getGroupChildNames ($groupName)
 
 getChildData ($alias, $key='')
 
 getUiId ($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)
 
 getJsId ($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)
 
 getUrl ($route='', $params=[])
 
 getViewFileUrl ($fileId, array $params=[])
 
 formatDate ( $date=null, $format=\IntlDateFormatter::SHORT, $showTime=false, $timezone=null)
 
 formatTime ( $time=null, $format=\IntlDateFormatter::SHORT, $showDate=false)
 
 getModuleName ()
 
 escapeHtml ($data, $allowedTags=null)
 
 escapeJs ($string)
 
 escapeHtmlAttr ($string, $escapeSingleQuote=true)
 
 escapeCss ($string)
 
 stripTags ($data, $allowableTags=null, $allowHtmlEntities=false)
 
 escapeUrl ($string)
 
 escapeXssInUrl ($data)
 
 escapeQuote ($data, $addSlashes=false)
 
 escapeJsQuote ($data, $quote='\'')
 
 getNameInLayout ()
 
 getCacheKeyInfo ()
 
 getCacheKey ()
 
 getVar ($name, $module=null)
 
 isScopePrivate ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 
- Public Member Functions inherited from BlockInterface
 toHtml ()
 
- Public Member Functions inherited from BlockInterface
 addData (array $arr)
 
 setData ($key, $value=null)
 

Data Fields

const DISPLAY_TYPE_ALL_PRODUCTS = 'all_products'
 
const DISPLAY_TYPE_NEW_PRODUCTS = 'new_products'
 
const DEFAULT_SHOW_PAGER = false
 
const DEFAULT_PRODUCTS_PER_PAGE = 5
 
const PAGE_VAR_NAME = 'np'
 
- Data Fields inherited from NewProduct
const DEFAULT_PRODUCTS_COUNT = 10
 
- Data Fields inherited from Template
const XML_PATH_TEMPLATE_ALLOW_SYMLINK = 'dev/template/allow_symlink'
 
- Data Fields inherited from AbstractBlock
const CACHE_GROUP = \Magento\Framework\App\Cache\Type\Block::TYPE_IDENTIFIER
 
const CACHE_KEY_PREFIX = 'BLOCK_'
 

Protected Member Functions

 _getProductCollection ()
 
 getPageSize ()
 
- Protected Member Functions inherited from NewProduct
 _construct ()
 
 _beforeToHtml ()
 
- Protected Member Functions inherited from AbstractProduct
 _addProductAttributesAndPrices (\Magento\Catalog\Model\ResourceModel\Product\Collection $collection)
 
 getDetailsRendererList ()
 
- Protected Member Functions inherited from Template
 _construct ()
 
 _toHtml ()
 
 getRootDirectory ()
 
 getMediaDirectory ()
 
- Protected Member Functions inherited from AbstractBlock
 _construct ()
 
 _prepareLayout ()
 
 _beforeToHtml ()
 
 _afterToHtml ($html)
 
 _toHtml ()
 
 _getNotFoundUrl ($route='', $params=['_direct'=> 'core/index/notFound'])
 
 getCacheTags ()
 
 getCacheLifetime ()
 
 _loadCache ()
 
 _saveCache ($data)
 
 _getSidPlaceholder ($cacheKey=null)
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_pager
 
- Protected Attributes inherited from NewProduct
 $_productsCount
 
 $httpContext
 
 $_catalogProductVisibility
 
 $_productCollectionFactory
 
- Protected Attributes inherited from AbstractProduct
 $_priceBlock = []
 
 $_useLinkForAsLowAs = true
 
 $_defaultColumnCount = 3
 
 $_columnCountLayoutDepend = []
 
 $_coreRegistry
 
 $_taxData
 
 $_catalogConfig
 
 $_mathRandom
 
 $_cartHelper
 
 $_wishlistHelper
 
 $_compareProduct
 
 $_imageHelper
 
 $reviewRenderer
 
 $stockRegistry
 
 $imageBuilder
 
- Protected Attributes inherited from Template
 $_viewVars = []
 
 $_baseUrl
 
 $_jsUrl
 
 $_allowSymlinks
 
 $_filesystem
 
 $_template
 
 $templateEnginePool
 
 $_storeManager
 
 $_appState
 
 $directory
 
 $templateContext
 
 $pageConfig
 
 $resolver
 
 $validator
 
- Protected Attributes inherited from AbstractBlock
 $_design
 
 $_session
 
 $_sidResolver
 
 $_nameInLayout
 
 $_layout
 
 $jsLayout = []
 
 $_request
 
 $_urlBuilder
 
 $_eventManager
 
 $_frontController
 
 $_assetRepo
 
 $_viewConfig
 
 $_cacheState
 
 $_logger
 
 $_escaper
 
 $filterManager
 
 $_localeDate
 
 $inlineTranslation
 
 $_isScopePrivate = false
 
 $_scopeConfig
 
 $_cache
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Public Member Functions inherited from AbstractBlock
static extractModuleName ($className)
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

New products widget

Definition at line 11 of file NewWidget.php.

Constructor & Destructor Documentation

◆ __construct()

__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 
)

NewWidget constructor.

Parameters
\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 | null$serializer

Definition at line 62 of file NewWidget.php.

69  {
70  parent::__construct(
71  $context,
72  $productCollectionFactory,
73  $catalogProductVisibility,
75  $data
76  );
77  $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
78  ->get(\Magento\Framework\Serialize\Serializer\Json::class);
79  }

Member Function Documentation

◆ _getProductCollection()

_getProductCollection ( )
protected

Product collection initialize process

Returns
\Magento\Catalog\Model\ResourceModel\Product\Collection|Object|\Magento\Framework\Data\Collection

Definition at line 86 of file NewWidget.php.

87  {
88  switch ($this->getDisplayType()) {
90  $collection = parent::_getProductCollection()
91  ->setPageSize($this->getPageSize())
92  ->setCurPage($this->getCurrentPage());
93  break;
94  default:
95  $collection = $this->_getRecentlyAddedProductsCollection();
96  break;
97  }
98  return $collection;
99  }

◆ getCacheKeyInfo()

getCacheKeyInfo ( )

Get key pieces for caching block content

Returns
array

Definition at line 135 of file NewWidget.php.

136  {
137  return array_merge(
138  parent::getCacheKeyInfo(),
139  [
140  $this->getDisplayType(),
141  $this->getProductsPerPage(),
142  intval($this->getRequest()->getParam($this->getData('page_var_name'), 1)),
143  $this->serializer->serialize($this->getRequest()->getParams())
144  ]
145  );
146  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getCurrentPage()

getCurrentPage ( )

Get number of current page based on query value

Returns
int

Definition at line 125 of file NewWidget.php.

126  {
127  return abs((int)$this->getRequest()->getParam($this->getData('page_var_name')));
128  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getDisplayType()

getDisplayType ( )

Retrieve display type for products

Returns
string

Definition at line 153 of file NewWidget.php.

154  {
155  if (!$this->hasData('display_type')) {
156  $this->setData('display_type', self::DISPLAY_TYPE_ALL_PRODUCTS);
157  }
158  return $this->getData('display_type');
159  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getPagerHtml()

getPagerHtml ( )

Render pagination HTML

Returns
string

Definition at line 215 of file NewWidget.php.

216  {
217  if ($this->showPager()) {
218  if (!$this->_pager) {
219  $this->_pager = $this->getLayout()->createBlock(
220  \Magento\Catalog\Block\Product\Widget\Html\Pager::class,
221  'widget.new.product.list.pager'
222  );
223 
224  $this->_pager->setUseContainer(true)
225  ->setShowAmounts(true)
226  ->setShowPerPage(false)
227  ->setPageVarName($this->getData('page_var_name'))
228  ->setLimit($this->getProductsPerPage())
229  ->setTotalLimit($this->getProductsCount())
230  ->setCollection($this->getProductCollection());
231  }
232  if ($this->_pager instanceof \Magento\Framework\View\Element\AbstractBlock) {
233  return $this->_pager->toHtml();
234  }
235  }
236  return '';
237  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getPageSize()

getPageSize ( )
protected

Retrieve how many products should be displayed on page

Returns
int

Definition at line 205 of file NewWidget.php.

◆ getProductsCount()

getProductsCount ( )

Retrieve how many products should be displayed

Returns
int

Definition at line 166 of file NewWidget.php.

167  {
168  if (!$this->hasData('products_count')) {
169  return parent::getProductsCount();
170  }
171  return $this->getData('products_count');
172  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getProductsPerPage()

getProductsPerPage ( )

Retrieve how many products should be displayed

Returns
int

Definition at line 179 of file NewWidget.php.

180  {
181  if (!$this->hasData('products_per_page')) {
182  $this->setData('products_per_page', self::DEFAULT_PRODUCTS_PER_PAGE);
183  }
184  return $this->getData('products_per_page');
185  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ showPager()

showPager ( )

Return flag whether pager need to be shown or not

Returns
bool

Definition at line 192 of file NewWidget.php.

193  {
194  if (!$this->hasData('show_pager')) {
195  $this->setData('show_pager', self::DEFAULT_SHOW_PAGER);
196  }
197  return (bool)$this->getData('show_pager');
198  }
getData($key='', $index=null)
Definition: DataObject.php:119

Field Documentation

◆ $_pager

$_pager
protected

Definition at line 45 of file NewWidget.php.

◆ DEFAULT_PRODUCTS_PER_PAGE

const DEFAULT_PRODUCTS_PER_PAGE = 5

Default value for products per page

Definition at line 31 of file NewWidget.php.

◆ DEFAULT_SHOW_PAGER

const DEFAULT_SHOW_PAGER = false

Default value whether show pager or not

Definition at line 26 of file NewWidget.php.

◆ DISPLAY_TYPE_ALL_PRODUCTS

const DISPLAY_TYPE_ALL_PRODUCTS = 'all_products'

Display products type - all products

Definition at line 16 of file NewWidget.php.

◆ DISPLAY_TYPE_NEW_PRODUCTS

const DISPLAY_TYPE_NEW_PRODUCTS = 'new_products'

Display products type - new products

Definition at line 21 of file NewWidget.php.

◆ PAGE_VAR_NAME

const PAGE_VAR_NAME = 'np'

Name of request parameter for page number value

Deprecated:

Definition at line 38 of file NewWidget.php.


The documentation for this class was generated from the following file: