Skip to content

Commit ed59f77

Browse files
authored
Merge pull request #88 from mageplaza/2.3-develop
v2.0.10
2 parents c0baca9 + f5169e9 commit ed59f77

15 files changed

+547
-293
lines changed

Block/AbstractSlider.php

+136-62
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Magento\Catalog\Model\Product\Visibility;
2929
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
3030
use Magento\Catalog\Pricing\Price\FinalPrice;
31+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
3132
use Magento\Framework\App\ActionInterface;
3233
use Magento\Framework\App\Http\Context as HttpContext;
3334
use Magento\Framework\App\ObjectManager;
@@ -38,6 +39,8 @@
3839
use Magento\Framework\Pricing\Render;
3940
use Magento\Framework\Stdlib\DateTime\DateTime;
4041
use Magento\Framework\Url\EncoderInterface;
42+
use Magento\Framework\View\LayoutFactory;
43+
use Magento\GroupedProduct\Model\Product\Type\Grouped;
4144
use Magento\Widget\Block\BlockInterface;
4245
use Mageplaza\Productslider\Helper\Data;
4346
use Mageplaza\Productslider\Model\Config\Source\Additional;
@@ -48,37 +51,50 @@
4851
*/
4952
abstract class AbstractSlider extends AbstractProduct implements BlockInterface, IdentityInterface
5053
{
51-
private $priceCurrency;
52-
5354
/**
5455
* @var DateTime
5556
*/
5657
protected $_date;
57-
5858
/**
5959
* @var Data
6060
*/
6161
protected $_helperData;
62-
6362
/**
6463
* @var CollectionFactory
6564
*/
6665
protected $_productCollectionFactory;
67-
6866
/**
6967
* @var Visibility
7068
*/
7169
protected $_catalogProductVisibility;
72-
7370
/**
7471
* @var HttpContext
7572
*/
7673
protected $httpContext;
77-
7874
/**
7975
* @var EncoderInterface|null
8076
*/
8177
protected $urlEncoder;
78+
/**
79+
* @var Grouped
80+
*/
81+
protected $grouped;
82+
/**
83+
* @var Configurable
84+
*/
85+
protected $configurable;
86+
/**
87+
* @var
88+
*/
89+
protected $rendererListBlock;
90+
/**
91+
* @var
92+
*/
93+
private $priceCurrency;
94+
/**
95+
* @var LayoutFactory
96+
*/
97+
private $layoutFactory;
8298

8399
/**
84100
* AbstractSlider constructor.
@@ -90,6 +106,9 @@ abstract class AbstractSlider extends AbstractProduct implements BlockInterface,
90106
* @param Data $helperData
91107
* @param HttpContext $httpContext
92108
* @param EncoderInterface $urlEncoder
109+
* @param Grouped $grouped
110+
* @param Configurable $configurable
111+
* @param LayoutFactory $layoutFactory
93112
* @param array $data
94113
*/
95114
public function __construct(
@@ -100,6 +119,9 @@ public function __construct(
100119
Data $helperData,
101120
HttpContext $httpContext,
102121
EncoderInterface $urlEncoder,
122+
Grouped $grouped,
123+
Configurable $configurable,
124+
LayoutFactory $layoutFactory,
103125
array $data = []
104126
) {
105127
$this->_productCollectionFactory = $productCollectionFactory;
@@ -108,30 +130,13 @@ public function __construct(
108130
$this->_helperData = $helperData;
109131
$this->httpContext = $httpContext;
110132
$this->urlEncoder = $urlEncoder;
133+
$this->grouped = $grouped;
134+
$this->configurable = $configurable;
135+
$this->layoutFactory = $layoutFactory;
111136

112137
parent::__construct($context, $data);
113138
}
114139

115-
/**
116-
* {@inheritdoc}
117-
*/
118-
protected function _construct()
119-
{
120-
parent::_construct();
121-
122-
$this->addData([
123-
'cache_lifetime' => $this->getSlider() ? $this->getSlider()->getTimeCache() : 86400,
124-
'cache_tags' => [Product::CACHE_TAG]
125-
]);
126-
127-
$this->setTemplate('Mageplaza_Productslider::productslider.phtml');
128-
}
129-
130-
/**
131-
* @return mixed
132-
*/
133-
abstract public function getProductCollection();
134-
135140
/**
136141
* Get Key pieces for caching block content
137142
*
@@ -150,34 +155,31 @@ public function getCacheKeyInfo()
150155
}
151156

152157
/**
153-
* @return array|mixed
158+
* {@inheritdoc}
154159
*/
155-
public function getDisplayAdditional()
160+
protected function _construct()
156161
{
157-
if ($this->getSlider()) {
158-
$display = $this->getSlider()->getDisplayAdditional();
159-
} else {
160-
$display = $this->_helperData->getModuleConfig('general/display_information');
161-
}
162+
parent::_construct();
162163

163-
if (!is_array($display)) {
164-
$display = explode(',', $display);
165-
}
164+
$this->addData([
165+
'cache_lifetime' => $this->getSlider() ? $this->getSlider()->getTimeCache() : 86400,
166+
'cache_tags' => [Product::CACHE_TAG]
167+
]);
166168

167-
return $display;
169+
$this->setTemplate('Mageplaza_Productslider::productslider.phtml');
168170
}
169171

170172
/**
171-
* @return mixed
173+
* Get Slider Id
174+
* @return string
172175
*/
173-
private function getPriceCurrency()
176+
public function getSliderId()
174177
{
175-
if ($this->priceCurrency === null) {
176-
$this->priceCurrency = ObjectManager::getInstance()
177-
->get(PriceCurrencyInterface::class);
178+
if ($this->getSlider()) {
179+
return $this->getSlider()->getSliderId();
178180
}
179181

180-
return $this->priceCurrency;
182+
return uniqid('-', false);
181183
}
182184

183185
/**
@@ -209,12 +211,21 @@ public function canShowPrice()
209211
}
210212

211213
/**
212-
* @return bool|\Magento\Framework\View\Element\BlockInterface
213-
* @throws LocalizedException
214+
* @return array|mixed
214215
*/
215-
protected function getPriceRender()
216+
public function getDisplayAdditional()
216217
{
217-
return $this->getLayout()->getBlock('product.price.render.default');
218+
if ($this->getSlider()) {
219+
$display = $this->getSlider()->getDisplayAdditional();
220+
} else {
221+
$display = $this->_helperData->getModuleConfig('general/display_information');
222+
}
223+
224+
if (!is_array($display)) {
225+
$display = explode(',', $display);
226+
}
227+
228+
return $display;
218229
}
219230

220231
/**
@@ -246,7 +257,7 @@ public function getProductPriceHtml(
246257
: true;
247258

248259
/** @var Render $priceRender */
249-
$priceRender = $this->getLayout()->getBlock('product.price.render.default');
260+
$priceRender = $this->getPriceRender();
250261
if (!$priceRender) {
251262
$priceRender = $this->getLayout()->createBlock(
252263
Render::class,
@@ -263,32 +274,41 @@ public function getProductPriceHtml(
263274
}
264275

265276
/**
266-
* @return bool
277+
* @return bool|\Magento\Framework\View\Element\BlockInterface
278+
* @throws LocalizedException
267279
*/
268-
public function canShowReview()
280+
protected function getPriceRender()
269281
{
270-
return in_array(Additional::SHOW_REVIEW, $this->getDisplayAdditional(), true);
282+
return $this->getLayout()->getBlock('product.price.render.default');
271283
}
272284

273285
/**
274-
* @return bool
286+
* @return mixed
275287
*/
276-
public function canShowAddToCart()
288+
private function getPriceCurrency()
277289
{
278-
return in_array(Additional::SHOW_CART, $this->getDisplayAdditional(), true);
290+
if ($this->priceCurrency === null) {
291+
$this->priceCurrency = ObjectManager::getInstance()
292+
->get(PriceCurrencyInterface::class);
293+
}
294+
295+
return $this->priceCurrency;
279296
}
280297

281298
/**
282-
* Get Slider Id
283-
* @return string
299+
* @return bool
284300
*/
285-
public function getSliderId()
301+
public function canShowReview()
286302
{
287-
if ($this->getSlider()) {
288-
return $this->getSlider()->getSliderId();
289-
}
303+
return in_array(Additional::SHOW_REVIEW, $this->getDisplayAdditional(), true);
304+
}
290305

291-
return uniqid('-', false);
306+
/**
307+
* @return bool
308+
*/
309+
public function canShowAddToCart()
310+
{
311+
return in_array(Additional::SHOW_CART, $this->getDisplayAdditional(), true);
292312
}
293313

294314
/**
@@ -437,6 +457,11 @@ public function getIdentities()
437457
return $identities ?: [Product::CACHE_TAG];
438458
}
439459

460+
/**
461+
* @return mixed
462+
*/
463+
abstract public function getProductCollection();
464+
440465
/**
441466
* Get Product Count is displayed
442467
*
@@ -454,4 +479,53 @@ public function getProductsCount()
454479

455480
return 5;
456481
}
482+
483+
/**
484+
* @param $collection
485+
*
486+
* @return array
487+
*/
488+
public function getProductParentIds($collection)
489+
{
490+
$productIds = [];
491+
492+
foreach ($collection as $product) {
493+
if (isset($product->getData()['entity_id'])) {
494+
$productId = $product->getData()['entity_id'];
495+
} else {
496+
$productId = $product->getProductId();
497+
}
498+
499+
$parentIdsGroup = $this->grouped->getParentIdsByChild($productId);
500+
$parentIdsConfig = $this->configurable->getParentIdsByChild($productId);
501+
502+
if (!empty($parentIdsGroup)) {
503+
$productIds[] = $parentIdsGroup;
504+
} elseif (!empty($parentIdsConfig)) {
505+
$productIds[] = $parentIdsConfig[0];
506+
} else {
507+
$productIds[] = $productId;
508+
}
509+
}
510+
511+
return $productIds;
512+
}
513+
514+
/**
515+
* @return bool|\Magento\Framework\View\Element\BlockInterface|\Magento\Framework\View\Element\RendererList
516+
* @throws LocalizedException
517+
*/
518+
protected function getDetailsRendererList()
519+
{
520+
if (empty($this->rendererListBlock)) {
521+
$layout = $this->layoutFactory->create(['cacheable' => false]);
522+
$layout->getUpdate()->addHandle('catalog_widget_product_list')->load();
523+
$layout->generateXml();
524+
$layout->generateElements();
525+
526+
$this->rendererListBlock = $layout->getBlock('category.product.type.widget.details.renderers');
527+
}
528+
529+
return $this->rendererListBlock;
530+
}
457531
}

Block/Adminhtml/Config/Field/Responsive.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class Responsive extends AbstractFieldArray
3434
*/
3535
protected function _prepareToRender()
3636
{
37-
$this->addColumn('size', ['label' => __('Screen size max'), 'renderer' => false]);
38-
$this->addColumn('items', ['label' => __('Number of items'), 'renderer' => false]);
37+
$this->addColumn('size', ['label' => __('Screen size max'), 'renderer' => false, 'class' => 'required-entry validate-number validate-greater-than-zero']);
38+
$this->addColumn('items', ['label' => __('Number of items'), 'renderer' => false, 'class' => 'required-entry validate-number validate-greater-than-zero']);
3939

4040
$this->_addAfter = false;
4141
$this->_addButtonLabel = __('Add');

Block/Adminhtml/Slider/Edit/Tab/Design.php

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ protected function _prepareForm()
111111
'name' => 'limit_number',
112112
'label' => __('Limit the number of products'),
113113
'title' => __('Limit the number of products'),
114+
'class' => 'validate-number validate-zero-or-greater'
114115
]);
115116

116117
$fieldset->addField('display_additional', 'multiselect', [

0 commit comments

Comments
 (0)