Skip to content

Commit 6b459ad

Browse files
authored
Merge pull request #96 from mageplaza/2.4-develop
2.4 develop
2 parents 2aa5b92 + 622033b commit 6b459ad

File tree

17 files changed

+790
-546
lines changed

17 files changed

+790
-546
lines changed

Block/AbstractSlider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public function getDisplayAdditional()
230230
}
231231

232232
if (!is_array($display)) {
233-
$display = explode(',', $display);
233+
$display = explode(',', $display ?: '');
234234
}
235235

236236
return $display;

Block/CustomProducts.php

100644100755
+2-2
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ public function __construct(
8888
*/
8989
public function getProductCollection()
9090
{
91-
$productIds = $this->getSlider()->getProductIds();
91+
$productIds = $this->getSlider()->getProductIds();
9292
$visibleProducts = $this->_catalogProductVisibility->getVisibleInCatalogIds();
9393
if (!is_array($productIds)) {
94-
$productIds = explode('&', $productIds);
94+
$productIds = explode('&', (string) $productIds);
9595
}
9696

9797
if (empty($productIds)) {

Controller/Adminhtml/Slider/Save.php

100644100755
+5-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
use Magento\Framework\Stdlib\DateTime\Filter\Date;
3232
use Mageplaza\Productslider\Controller\Adminhtml\Slider;
3333
use Mageplaza\Productslider\Model\SliderFactory;
34-
use Zend_Filter_Input;
34+
use Magento\Framework\Filter\FilterInput;
3535

3636
/**
3737
* Class Save
@@ -67,7 +67,7 @@ public function __construct(
6767
Date $dateFilter,
6868
DataPersistorInterface $dataPersistor
6969
) {
70-
$this->_dateFilter = $dateFilter;
70+
$this->_dateFilter = $dateFilter;
7171
$this->dataPersistor = $dataPersistor;
7272

7373
parent::__construct($context, $sliderFactory, $coreRegistry);
@@ -80,7 +80,7 @@ public function execute()
8080
{
8181
if ($data = $this->getRequest()->getPost('slider')) {
8282
try {
83-
$data = $this->_filterData($data);
83+
$data = $this->_filterData($data);
8484
$slider = $this->_initSlider();
8585

8686
$validateResult = $slider->validateData(new DataObject($data));
@@ -138,8 +138,8 @@ public function execute()
138138
*/
139139
protected function _filterData($data)
140140
{
141-
$inputFilter = new Zend_Filter_Input(['from_date' => $this->_dateFilter], [], $data);
142-
$data = $inputFilter->getUnescaped();
141+
$inputFilter = new FilterInput(['from_date' => $this->_dateFilter], [], $data);
142+
$data = $inputFilter->getUnescaped();
143143

144144
if (isset($data['responsive_items'])) {
145145
unset($data['responsive_items']['__empty']);

Model/ResourceModel/Slider.php

100644100755
+31-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
2626
use Magento\Framework\Model\ResourceModel\Db\Context;
2727
use Mageplaza\Productslider\Helper\Data;
28+
use Magento\Framework\Stdlib\DateTime\DateTime;
29+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
2830

2931
/**
3032
* Class Slider
@@ -38,18 +40,35 @@ class Slider extends AbstractDb
3840
protected $helper;
3941

4042
/**
41-
* Slider constructor.
43+
* Date model
44+
*
45+
* @var DateTime
46+
*/
47+
protected $date;
48+
49+
/**
50+
* @var TimezoneInterface
51+
*/
52+
protected $timezone;
53+
54+
/**
4255
*
4356
* @param Context $context
4457
* @param Data $helper
58+
* @param DateTime $date
59+
* @param TimezoneInterface $timezone
4560
* @param null $connectionName
4661
*/
4762
public function __construct(
4863
Context $context,
4964
Data $helper,
65+
DateTime $date,
66+
TimezoneInterface $timezone,
5067
$connectionName = null
5168
) {
52-
$this->helper = $helper;
69+
$this->helper = $helper;
70+
$this->date = $date;
71+
$this->timezone = $timezone;
5372

5473
parent::__construct($context, $connectionName);
5574
}
@@ -65,6 +84,7 @@ protected function _construct()
6584
}
6685

6786
/**
87+
*
6888
* @inheritdoc
6989
*/
7090
protected function _beforeSave(AbstractModel $object)
@@ -91,6 +111,15 @@ protected function _beforeSave(AbstractModel $object)
91111
$object->setResponsiveItems($this->helper->serialize([]));
92112
}
93113

114+
if ($object->isObjectNew()) {
115+
$object->setFromDate($object->getFromDate() . $this->timezone->date()->format('H:i:s'));
116+
}
117+
118+
$toDate = $object->getToDate();
119+
$initialDateTime = new \DateTime($toDate);
120+
$initialDateTime->setTime(23, 59, 59);
121+
$toDate = $initialDateTime->format('M d, Y h:i:s A');
122+
$object->setToDate($toDate);
94123
return parent::_beforeSave($object);
95124
}
96125

Observer/AddBlock.php

+17-5
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public function __construct(
6161
Data $helperData,
6262
ProductType $productType
6363
) {
64-
$this->request = $request;
65-
$this->helperData = $helperData;
64+
$this->request = $request;
65+
$this->helperData = $helperData;
6666
$this->productType = $productType;
6767
}
6868

@@ -81,9 +81,18 @@ public function execute(Observer $observer)
8181
]);
8282
if ($type !== false) {
8383
/** @var Layout $layout */
84-
$layout = $observer->getEvent()->getLayout();
84+
$layout = $observer->getEvent()->getLayout();
8585
$fullActionName = $this->request->getFullActionName();
86-
$output = $observer->getTransport()->getOutput();
86+
$output = $observer->getTransport()->getOutput();
87+
$allBlocks = $layout->getAllBlocks();
88+
$cmsHtml = '';
89+
if ($fullActionName === 'catalog_category_view') {
90+
foreach ($allBlocks as $item) {
91+
if ($item->getModuleName() === 'Magento_Cms' && $item->getText()) {
92+
$cmsHtml = $item->getText();
93+
}
94+
}
95+
}
8796
foreach ($this->helperData->getActiveSliders() as $slider) {
8897
[$pageType, $location] = explode('.', $slider->getLocation());
8998
if ($fullActionName == $pageType || $pageType == 'allpage') {
@@ -92,10 +101,13 @@ public function execute(Observer $observer)
92101
->toHtml();
93102

94103
if (strpos($location, $type) !== false) {
95-
if (strpos($location, 'top') !== false) {
104+
if (strpos($location, 'top') !== false && $fullActionName === 'catalog_category_view') {
105+
$output = "<div id=\"mageplaza-productslider-block-before-{$type}-{$slider->getId()}\">$content</div>" . $output . $cmsHtml;
106+
} else if (strpos($location, 'top') !== false) {
96107
$output = "<div id=\"mageplaza-productslider-block-before-{$type}-{$slider->getId()}\">$content</div>" . $output;
97108
} else {
98109
$output .= "<div id=\"mageplaza-productslider-block-after-{$type}-{$slider->getId()}\">$content</div>";
110+
99111
}
100112
}
101113
}

Plugin/Block/Widget/Block.php

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/**
3+
* Mageplaza
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Mageplaza.com license that is
8+
* available through the world-wide-web at this URL:
9+
* https://www.mageplaza.com/LICENSE.txt
10+
*
11+
* DISCLAIMER
12+
*
13+
* Do not edit or add to this file if you wish to upgrade this extension to newer
14+
* version in the future.
15+
*
16+
* @category Mageplaza
17+
* @package Mageplaza_Productslider
18+
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
19+
* @license https://www.mageplaza.com/LICENSE.txt
20+
*/
21+
22+
namespace Mageplaza\Productslider\Plugin\Block\Widget;
23+
24+
use Magento\Cms\Block\Widget\Block as WidgetBlock;
25+
use Mageplaza\Productslider\Helper\Data as HelperData;
26+
use Magento\Framework\App\RequestInterface;
27+
28+
/**
29+
* Class Block
30+
* @package Mageplaza\Productslider\Plugin\Block\Widget
31+
*/
32+
class Block
33+
{
34+
/**
35+
* @var HelperData
36+
*/
37+
protected $helperData;
38+
39+
/**
40+
* @var RequestInterface
41+
*/
42+
protected $request;
43+
44+
/**
45+
* @param HelperData $helperData
46+
* @param RequestInterface $request
47+
*/
48+
public function __construct(
49+
HelperData $helperData,
50+
RequestInterface $request
51+
) {
52+
$this->helperData = $helperData;
53+
$this->request = $request;
54+
}
55+
56+
/**
57+
* @param WidgetBlock $subject
58+
* @param $result
59+
*
60+
* @return mixed|void
61+
*/
62+
public function afterToHtml(WidgetBlock $subject, $result)
63+
{
64+
if ($this->helperData->isEnabled() && $this->request->getFullActionName() === 'cms_index_index') {
65+
return $result;
66+
}
67+
}
68+
}

Setup/InstallData.php

-89
This file was deleted.

0 commit comments

Comments
 (0)