Skip to content

Commit 514bec7

Browse files
Merge pull request #98 from mageplaza/2.4-develop
Release v4.0.5
2 parents 6b459ad + a1efac6 commit 514bec7

File tree

12 files changed

+978
-27
lines changed

12 files changed

+978
-27
lines changed

Block/AbstractSlider.php

+12-8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
*/
5252
abstract class AbstractSlider extends AbstractProduct implements BlockInterface, IdentityInterface
5353
{
54+
protected $_template = "Mageplaza_Productslider::productslider.phtml";
55+
5456
/**
5557
* @var DateTime
5658
*/
@@ -161,12 +163,14 @@ protected function _construct()
161163
{
162164
parent::_construct();
163165

164-
$this->addData([
165-
'cache_lifetime' => $this->getSlider() ? $this->getSlider()->getTimeCache() : 86400,
166-
'cache_tags' => [Product::CACHE_TAG]
167-
]);
168-
169-
$this->setTemplate('Mageplaza_Productslider::productslider.phtml');
166+
if ($this->_helperData->isHyvaTheme()) {
167+
$this->_template = 'Mageplaza_Productslider::hyva/productslider.phtml';
168+
} else {
169+
$this->addData([
170+
'cache_lifetime' => $this->getSlider() ? $this->getSlider()->getTimeCache() : 86400,
171+
'cache_tags' => [Product::CACHE_TAG]
172+
]);
173+
}
170174
}
171175

172176
/**
@@ -407,12 +411,12 @@ public function getResponsiveConfig()
407411
$responsiveOptions = '';
408412
foreach ($responsiveConfig as $config) {
409413
if (!empty($config['size']) && !empty($config['items'])) {
410-
$responsiveOptions .= $config['size'] . ':{items:' . $config['items'] . '},';
414+
$responsiveOptions .= $config['size'] . ':{'. ($this->_helperData->isHyvaTheme() ? 'perView' : 'items') . ':' . $config['items'] . '},';
411415
}
412416
}
413417
$responsiveOptions = rtrim($responsiveOptions, ',');
414418

415-
return 'responsive:{' . $responsiveOptions . '}';
419+
return ($this->_helperData->isHyvaTheme() ? 'breakpoints' : 'responsive') . ':{' . $responsiveOptions . '}';
416420
}
417421

418422
return '';

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

+22-11
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use Mageplaza\Productslider\Helper\Data;
3232
use Mageplaza\Productslider\Model\Config\Source\Additional;
3333
use Mageplaza\Productslider\Model\Slider;
34+
use function Ramsey\Uuid\v1;
3435

3536
/**
3637
* Class Design
@@ -98,49 +99,59 @@ protected function _prepareForm()
9899
);
99100

100101
$fieldset->addField('title', 'text', [
101-
'name' => 'title',
102+
'name' => 'title',
102103
'label' => __('Title'),
103104
'title' => __('Title'),
104105
]);
105106
$fieldset->addField('description', 'textarea', [
106-
'name' => 'description',
107+
'name' => 'description',
107108
'label' => __('Description'),
108109
'title' => __('Description'),
109110
]);
110111
$fieldset->addField('limit_number', 'text', [
111-
'name' => 'limit_number',
112+
'name' => 'limit_number',
112113
'label' => __('Limit the number of products'),
113114
'title' => __('Limit the number of products'),
114115
'class' => 'validate-digits'
115116
]);
116117

117118
$fieldset->addField('display_additional', 'multiselect', [
118-
'name' => 'display_additional',
119-
'label' => __('Display additional information'),
120-
'title' => __('Display additional information'),
119+
'name' => 'display_additional',
120+
'label' => __('Display additional information'),
121+
'title' => __('Display additional information'),
121122
'values' => $this->_additional->toOptionArray(),
122-
'note' => __('Select information or button(s) to display with products.')
123+
'note' => __('Select information or button(s) to display with products.')
123124
]);
124125

125126
$isResponsive = $fieldset->addField('is_responsive', 'select', [
126-
'name' => 'is_responsive',
127-
'label' => __('Is Responsive'),
128-
'title' => __('Is Responsive'),
127+
'name' => 'is_responsive',
128+
'label' => __('Is Responsive'),
129+
'title' => __('Is Responsive'),
129130
'options' => [
130131
'1' => __('Yes'),
131132
'0' => __('No'),
132133
'2' => __('Use Config')
133134
]
134135
]);
135136

137+
$isHyvaThemeAdmin = $this->_helperData->isHyvaThemeAdmin();
138+
if ($isHyvaThemeAdmin) {
139+
$note = 'When the screen size is smaller than <strong>Screen size max</strong>, the number of products on the slider will change according to <strong>Number of items</strong>.
140+
Default: 3 items.';
141+
142+
} else {
143+
$note = 'When the screen size is larger than <strong>Screen size max</strong>, the number of products on the slider will change according to <strong>Number of items</strong>
144+
Default: 3 items.';
145+
}
146+
136147
$responsiveItem = $fieldset->addField(
137148
'responsive_items',
138149
'Mageplaza\Productslider\Block\Adminhtml\Slider\Edit\Tab\Renderer\Responsive',
139150
[
140151
'name' => 'responsive_items',
141152
'label' => __('Max Items slider'),
142153
'title' => __('Max Items slider'),
143-
'note' => __('Default: 3 items.')
154+
'note' => __($note)
144155
]
145156
);
146157

Block/Widget/Slider.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ public function _construct()
105105
{
106106
parent::_construct();
107107

108-
$this->setTemplate('Mageplaza_Productslider::widget/productslider.phtml');
108+
if ($this->_helperData->isHyvaTheme()) {
109+
$this->_template = 'Mageplaza_Productslider::hyva/widget/productslider.phtml';
110+
}
109111
}
110112

111113
/**
@@ -221,4 +223,12 @@ public function getAllOptions()
221223
{
222224
return $this->_helperData->getAllOptions();
223225
}
226+
227+
/**
228+
* @return string
229+
*/
230+
public function getResponseValue()
231+
{
232+
return $this->_helperData->getResponseValue();
233+
}
224234
}

Helper/Data.php

+30-5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
use Magento\Framework\Exception\NoSuchEntityException;
2727
use Magento\Framework\ObjectManagerInterface;
2828
use Magento\Framework\Stdlib\DateTime\DateTime;
29+
use Magento\Framework\View\DesignInterface;
30+
use Magento\Framework\View\Design\Theme\ThemeProviderInterface;
2931
use Magento\Store\Model\StoreManagerInterface;
3032
use Mageplaza\Core\Helper\AbstractData;
3133
use Mageplaza\Productslider\Model\ResourceModel\Slider\Collection;
@@ -55,6 +57,11 @@ class Data extends AbstractData
5557
*/
5658
protected $sliderFactory;
5759

60+
/**
61+
* @var ThemeProviderInterface
62+
*/
63+
protected $themeProvider;
64+
5865
/**
5966
* Data constructor.
6067
*
@@ -64,18 +71,21 @@ class Data extends AbstractData
6471
* @param DateTime $date
6572
* @param HttpContext $httpContext
6673
* @param SliderFactory $sliderFactory
74+
* @param ThemeProviderInterface $themeProvider
6775
*/
6876
public function __construct(
6977
Context $context,
7078
ObjectManagerInterface $objectManager,
7179
StoreManagerInterface $storeManager,
7280
DateTime $date,
7381
HttpContext $httpContext,
74-
SliderFactory $sliderFactory
82+
SliderFactory $sliderFactory,
83+
ThemeProviderInterface $themeProvider
7584
) {
76-
$this->date = $date;
77-
$this->httpContext = $httpContext;
85+
$this->date = $date;
86+
$this->httpContext = $httpContext;
7887
$this->sliderFactory = $sliderFactory;
88+
$this->themeProvider = $themeProvider;
7989

8090
parent::__construct($context, $objectManager, $storeManager);
8191
}
@@ -143,12 +153,27 @@ public function getResponseValue()
143153

144154
foreach ($responsiveConfig as $config) {
145155
if (!empty($config['size']) && !empty($config['items'])) {
146-
$responsiveOptions .= $config['size'] . ':{items:' . $config['items'] . '},';
156+
$responsiveOptions .= $config['size'] . ':{'. ($this->isHyvaTheme() ? 'perView' : 'items') . ':' . $config['items'] . '},';
147157
}
148158
}
149159

150160
$responsiveOptions = rtrim($responsiveOptions, ',');
151161

152-
return 'responsive:{' . $responsiveOptions . '}';
162+
return ($this->isHyvaTheme() ? 'breakpoints' : 'responsive') . ':{' . $responsiveOptions . '}';
163+
}
164+
165+
/**
166+
* @return bool
167+
* @throws NoSuchEntityException
168+
*/
169+
public function isHyvaThemeAdmin()
170+
{
171+
$store = $this->storeManager->getStore();
172+
$themeId = $store->getConfig(DesignInterface::XML_PATH_THEME_ID);
173+
$theme = $this->themeProvider->getThemeById($themeId);
174+
$currentThemeCode = $theme->getCode();
175+
$isHyvaThemeAdmin = (strpos($currentThemeCode, 'Hyva') !== false);
176+
177+
return $isHyvaThemeAdmin;
153178
}
154179
}

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"name": "mageplaza/magento-2-product-slider",
33
"description": "Magento 2 Product Slider",
44
"require": {
5-
"mageplaza/module-core": "^1.5.4"
5+
"mageplaza/module-core": "^1.5.13"
66
},
77
"type": "magento2-module",
8-
"version": "4.0.4",
8+
"version": "4.0.5",
99
"license": "proprietary",
1010
"authors": [
1111
{

etc/adminhtml/system.xml

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
<label>Max Items slider</label>
5353
<frontend_model>Mageplaza\Productslider\Block\Adminhtml\Config\Field\Responsive</frontend_model>
5454
<backend_model>Magento\Config\Model\Config\Backend\Serialized\ArraySerialized</backend_model>
55+
<comment>With Hyva theme: When the screen size is smaller than Screen size max, the number of products on the slider will change according to Number of items.
56+
With Luma theme: it will be larger than the Maximum Screen Size.
57+
</comment>
5558
<depends>
5659
<field id="responsive">1</field>
5760
</depends>

etc/config.xml

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
2424
<default>
2525
<productslider>
26+
<module>
27+
<user_guide>magento/magento-2-product-slider</user_guide>
28+
</module>
2629
<general>
2730
<enabled>1</enabled>
2831
</general>

etc/csp_whitelist.xml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Mageplaza
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the Mageplaza.com license that is
9+
* available through the world-wide-web at this URL:
10+
* https://www.mageplaza.com/LICENSE.txt
11+
*
12+
* DISCLAIMER
13+
*
14+
* Do not edit or add to this file if you wish to upgrade this extension to newer
15+
* version in the future.
16+
*
17+
* @category Mageplaza
18+
* @package Mageplaza_Productslider
19+
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
20+
* @license https://www.mageplaza.com/LICENSE.txt
21+
*/
22+
-->
23+
<csp_whitelist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24+
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Csp:etc/csp_whitelist.xsd">
25+
<policies>
26+
<policy id="script-src">
27+
<values>
28+
<value id="jsdelivr" type="host">https://cdn.jsdelivr.net</value>
29+
</values>
30+
</policy>
31+
</policies>
32+
</csp_whitelist>

view/frontend/layout/hyva_default.xml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Mageplaza
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the Mageplaza.com license that is
9+
* available through the world-wide-web at this URL:
10+
* https://www.mageplaza.com/LICENSE.txt
11+
*
12+
* DISCLAIMER
13+
*
14+
* Do not edit or add to this file if you wish to upgrade this extension to newer
15+
* version in the future.
16+
*
17+
* @category Mageplaza
18+
* @package Mageplaza_Productslider
19+
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
20+
* @license https://www.mageplaza.com/LICENSE.txt
21+
*/
22+
-->
23+
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
24+
<update handle="hyva_mp_add_js_css" />
25+
<body>
26+
<referenceBlock name="mp_add_js_css">
27+
<action method="setFiles">
28+
<argument name="files" xsi:type="array">
29+
<item name="hyva_style_css" xsi:type="string">Mageplaza_Productslider::css/hyva_style.css</item>
30+
</argument>
31+
</action>
32+
</referenceBlock>
33+
</body>
34+
</page>

0 commit comments

Comments
 (0)