Skip to content

Commit

Permalink
Merge pull request #96 from mageplaza/2.4-develop
Browse files Browse the repository at this point in the history
2.4 develop
  • Loading branch information
phutx authored Jul 25, 2023
2 parents 2aa5b92 + 622033b commit 6b459ad
Show file tree
Hide file tree
Showing 17 changed files with 790 additions and 546 deletions.
2 changes: 1 addition & 1 deletion Block/AbstractSlider.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public function getDisplayAdditional()
}

if (!is_array($display)) {
$display = explode(',', $display);
$display = explode(',', $display ?: '');
}

return $display;
Expand Down
4 changes: 2 additions & 2 deletions Block/CustomProducts.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ public function __construct(
*/
public function getProductCollection()
{
$productIds = $this->getSlider()->getProductIds();
$productIds = $this->getSlider()->getProductIds();
$visibleProducts = $this->_catalogProductVisibility->getVisibleInCatalogIds();
if (!is_array($productIds)) {
$productIds = explode('&', $productIds);
$productIds = explode('&', (string) $productIds);
}

if (empty($productIds)) {
Expand Down
10 changes: 5 additions & 5 deletions Controller/Adminhtml/Slider/Save.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
use Magento\Framework\Stdlib\DateTime\Filter\Date;
use Mageplaza\Productslider\Controller\Adminhtml\Slider;
use Mageplaza\Productslider\Model\SliderFactory;
use Zend_Filter_Input;
use Magento\Framework\Filter\FilterInput;

/**
* Class Save
Expand Down Expand Up @@ -67,7 +67,7 @@ public function __construct(
Date $dateFilter,
DataPersistorInterface $dataPersistor
) {
$this->_dateFilter = $dateFilter;
$this->_dateFilter = $dateFilter;
$this->dataPersistor = $dataPersistor;

parent::__construct($context, $sliderFactory, $coreRegistry);
Expand All @@ -80,7 +80,7 @@ public function execute()
{
if ($data = $this->getRequest()->getPost('slider')) {
try {
$data = $this->_filterData($data);
$data = $this->_filterData($data);
$slider = $this->_initSlider();

$validateResult = $slider->validateData(new DataObject($data));
Expand Down Expand Up @@ -138,8 +138,8 @@ public function execute()
*/
protected function _filterData($data)
{
$inputFilter = new Zend_Filter_Input(['from_date' => $this->_dateFilter], [], $data);
$data = $inputFilter->getUnescaped();
$inputFilter = new FilterInput(['from_date' => $this->_dateFilter], [], $data);
$data = $inputFilter->getUnescaped();

if (isset($data['responsive_items'])) {
unset($data['responsive_items']['__empty']);
Expand Down
33 changes: 31 additions & 2 deletions Model/ResourceModel/Slider.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
use Magento\Framework\Model\ResourceModel\Db\Context;
use Mageplaza\Productslider\Helper\Data;
use Magento\Framework\Stdlib\DateTime\DateTime;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;

/**
* Class Slider
Expand All @@ -38,18 +40,35 @@ class Slider extends AbstractDb
protected $helper;

/**
* Slider constructor.
* Date model
*
* @var DateTime
*/
protected $date;

/**
* @var TimezoneInterface
*/
protected $timezone;

/**
*
* @param Context $context
* @param Data $helper
* @param DateTime $date
* @param TimezoneInterface $timezone
* @param null $connectionName
*/
public function __construct(
Context $context,
Data $helper,
DateTime $date,
TimezoneInterface $timezone,
$connectionName = null
) {
$this->helper = $helper;
$this->helper = $helper;
$this->date = $date;
$this->timezone = $timezone;

parent::__construct($context, $connectionName);
}
Expand All @@ -65,6 +84,7 @@ protected function _construct()
}

/**
*
* @inheritdoc
*/
protected function _beforeSave(AbstractModel $object)
Expand All @@ -91,6 +111,15 @@ protected function _beforeSave(AbstractModel $object)
$object->setResponsiveItems($this->helper->serialize([]));
}

if ($object->isObjectNew()) {
$object->setFromDate($object->getFromDate() . $this->timezone->date()->format('H:i:s'));
}

$toDate = $object->getToDate();
$initialDateTime = new \DateTime($toDate);
$initialDateTime->setTime(23, 59, 59);
$toDate = $initialDateTime->format('M d, Y h:i:s A');
$object->setToDate($toDate);
return parent::_beforeSave($object);
}

Expand Down
22 changes: 17 additions & 5 deletions Observer/AddBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public function __construct(
Data $helperData,
ProductType $productType
) {
$this->request = $request;
$this->helperData = $helperData;
$this->request = $request;
$this->helperData = $helperData;
$this->productType = $productType;
}

Expand All @@ -81,9 +81,18 @@ public function execute(Observer $observer)
]);
if ($type !== false) {
/** @var Layout $layout */
$layout = $observer->getEvent()->getLayout();
$layout = $observer->getEvent()->getLayout();
$fullActionName = $this->request->getFullActionName();
$output = $observer->getTransport()->getOutput();
$output = $observer->getTransport()->getOutput();
$allBlocks = $layout->getAllBlocks();
$cmsHtml = '';
if ($fullActionName === 'catalog_category_view') {
foreach ($allBlocks as $item) {
if ($item->getModuleName() === 'Magento_Cms' && $item->getText()) {
$cmsHtml = $item->getText();
}
}
}
foreach ($this->helperData->getActiveSliders() as $slider) {
[$pageType, $location] = explode('.', $slider->getLocation());
if ($fullActionName == $pageType || $pageType == 'allpage') {
Expand All @@ -92,10 +101,13 @@ public function execute(Observer $observer)
->toHtml();

if (strpos($location, $type) !== false) {
if (strpos($location, 'top') !== false) {
if (strpos($location, 'top') !== false && $fullActionName === 'catalog_category_view') {
$output = "<div id=\"mageplaza-productslider-block-before-{$type}-{$slider->getId()}\">$content</div>" . $output . $cmsHtml;
} else if (strpos($location, 'top') !== false) {
$output = "<div id=\"mageplaza-productslider-block-before-{$type}-{$slider->getId()}\">$content</div>" . $output;
} else {
$output .= "<div id=\"mageplaza-productslider-block-after-{$type}-{$slider->getId()}\">$content</div>";

}
}
}
Expand Down
68 changes: 68 additions & 0 deletions Plugin/Block/Widget/Block.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Productslider
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\Productslider\Plugin\Block\Widget;

use Magento\Cms\Block\Widget\Block as WidgetBlock;
use Mageplaza\Productslider\Helper\Data as HelperData;
use Magento\Framework\App\RequestInterface;

/**
* Class Block
* @package Mageplaza\Productslider\Plugin\Block\Widget
*/
class Block
{
/**
* @var HelperData
*/
protected $helperData;

/**
* @var RequestInterface
*/
protected $request;

/**
* @param HelperData $helperData
* @param RequestInterface $request
*/
public function __construct(
HelperData $helperData,
RequestInterface $request
) {
$this->helperData = $helperData;
$this->request = $request;
}

/**
* @param WidgetBlock $subject
* @param $result
*
* @return mixed|void
*/
public function afterToHtml(WidgetBlock $subject, $result)
{
if ($this->helperData->isEnabled() && $this->request->getFullActionName() === 'cms_index_index') {
return $result;
}
}
}
89 changes: 0 additions & 89 deletions Setup/InstallData.php

This file was deleted.

Loading

0 comments on commit 6b459ad

Please sign in to comment.