Skip to content

Commit dfcc688

Browse files
authored
Merge pull request #70 from mageplaza/develop
Develop
2 parents c617a72 + a49dbdf commit dfcc688

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+536
-365
lines changed

Block/AbstractSlider.php

+42-9
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
use Magento\Catalog\Model\Product;
2828
use Magento\Catalog\Model\Product\Visibility;
2929
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
30+
use Magento\Framework\App\ActionInterface;
3031
use Magento\Framework\App\Http\Context as HttpContext;
3132
use Magento\Framework\Exception\NoSuchEntityException;
3233
use Magento\Framework\Stdlib\DateTime\DateTime;
34+
use Magento\Framework\Url\EncoderInterface;
3335
use Mageplaza\Productslider\Helper\Data;
3436
use Mageplaza\Productslider\Model\Config\Source\Additional;
3537

@@ -64,14 +66,21 @@ abstract class AbstractSlider extends AbstractProduct
6466
*/
6567
protected $httpContext;
6668

69+
/**
70+
* @var EncoderInterface|null
71+
*/
72+
protected $urlEncoder;
73+
6774
/**
6875
* AbstractSlider constructor.
76+
*
6977
* @param Context $context
7078
* @param CollectionFactory $productCollectionFactory
7179
* @param Visibility $catalogProductVisibility
7280
* @param DateTime $dateTime
7381
* @param Data $helperData
7482
* @param HttpContext $httpContext
83+
* @param EncoderInterface $urlEncoder
7584
* @param array $data
7685
*/
7786
public function __construct(
@@ -81,13 +90,15 @@ public function __construct(
8190
DateTime $dateTime,
8291
Data $helperData,
8392
HttpContext $httpContext,
93+
EncoderInterface $urlEncoder,
8494
array $data = []
8595
) {
8696
$this->_productCollectionFactory = $productCollectionFactory;
8797
$this->_catalogProductVisibility = $catalogProductVisibility;
88-
$this->_date = $dateTime;
89-
$this->_helperData = $helperData;
90-
$this->httpContext = $httpContext;
98+
$this->_date = $dateTime;
99+
$this->_helperData = $helperData;
100+
$this->httpContext = $httpContext;
101+
$this->urlEncoder = $urlEncoder;
91102

92103
parent::__construct($context, $data);
93104
}
@@ -146,6 +157,26 @@ public function getDisplayAdditional()
146157
return $display;
147158
}
148159

160+
/**
161+
* Get post parameters.
162+
*
163+
* @param Product $product
164+
*
165+
* @return array
166+
*/
167+
public function getAddToCartPostParams(Product $product)
168+
{
169+
$url = $this->getAddToCartUrl($product);
170+
171+
return [
172+
'action' => $url,
173+
'data' => [
174+
'product' => $product->getEntityId(),
175+
ActionInterface::PARAM_NAME_URL_ENCODED => $this->urlEncoder->encode($url),
176+
]
177+
];
178+
}
179+
149180
/**
150181
* @return bool
151182
*/
@@ -180,7 +211,7 @@ public function getSliderId()
180211
return $this->getSlider()->getSliderId();
181212
}
182213

183-
return time();
214+
return uniqid('-', false);
184215
}
185216

186217
/**
@@ -225,7 +256,7 @@ public function getDescription()
225256
public function getAllOptions()
226257
{
227258
$sliderOptions = '';
228-
$allConfig = $this->_helperData->getModuleConfig('slider_design');
259+
$allConfig = $this->_helperData->getModuleConfig('slider_design');
229260

230261
foreach ($allConfig as $key => $value) {
231262
if ($key === 'item_slider') {
@@ -238,7 +269,7 @@ public function getAllOptions()
238269
if (in_array($key, ['loop', 'nav', 'dots', 'lazyLoad', 'autoplay', 'autoplayHoverPause'])) {
239270
$value = $value ? 'true' : 'false';
240271
}
241-
$sliderOptions = $sliderOptions . $key . ':' . $value . ',';
272+
$sliderOptions .= $key . ':' . $value . ',';
242273
}
243274
}
244275

@@ -255,17 +286,19 @@ public function getResponsiveConfig()
255286
try {
256287
if ($slider->getIsResponsive() === '2') {
257288
return $this->_helperData->getResponseValue();
258-
} else {
259-
$responsiveConfig = $slider->getResponsiveItems() ? $this->_helperData->unserialize($slider->getResponsiveItems()) : [];
260289
}
290+
291+
$responsiveConfig = $slider->getResponsiveItems()
292+
? $this->_helperData->unserialize($slider->getResponsiveItems())
293+
: [];
261294
} catch (Exception $e) {
262295
$responsiveConfig = [];
263296
}
264297

265298
$responsiveOptions = '';
266299
foreach ($responsiveConfig as $config) {
267300
if ($config['size'] && $config['items']) {
268-
$responsiveOptions = $responsiveOptions . $config['size'] . ':{items:' . $config['items'] . '},';
301+
$responsiveOptions .= $config['size'] . ':{items:' . $config['items'] . '},';
269302
}
270303
}
271304
$responsiveOptions = rtrim($responsiveOptions, ',');

Block/Adminhtml/Config/Field/Responsive.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected function _prepareToRender()
3737
$this->addColumn('size', ['label' => __('Screen size max'), 'renderer' => false]);
3838
$this->addColumn('items', ['label' => __('Number of items'), 'renderer' => false]);
3939

40-
$this->_addAfter = false;
40+
$this->_addAfter = false;
4141
$this->_addButtonLabel = __('Add');
4242
}
4343
}

Block/Adminhtml/Slider.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class Slider extends Container
3636
*/
3737
protected function _construct()
3838
{
39-
$this->_controller = 'adminhtml_slider';
40-
$this->_blockGroup = 'Mageplaza_Productslider';
41-
$this->_headerText = __('Sliders');
39+
$this->_controller = 'adminhtml_slider';
40+
$this->_blockGroup = 'Mageplaza_Productslider';
41+
$this->_headerText = __('Sliders');
4242
$this->_addButtonLabel = __('Create New Slider');
4343
parent::_construct();
4444
}

Block/Adminhtml/Slider/Edit.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Edit extends Container
4040

4141
/**
4242
* Edit constructor.
43+
*
4344
* @param Registry $coreRegistry
4445
* @param Context $context
4546
* @param array $data
@@ -86,7 +87,7 @@ public function getSlider()
8687
*/
8788
protected function _construct()
8889
{
89-
$this->_objectId = 'id';
90+
$this->_objectId = 'id';
9091
$this->_blockGroup = 'Mageplaza_Productslider';
9192
$this->_controller = 'adminhtml_slider';
9293

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

+10-5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class Design extends Generic implements TabInterface
5555

5656
/**
5757
* Design constructor.
58+
*
5859
* @param Data $helperData
5960
* @param Additional $additional
6061
* @param Context $context
@@ -131,11 +132,15 @@ protected function _prepareForm()
131132
]
132133
]);
133134

134-
$responsiveItem = $fieldset->addField('responsive_items', 'Mageplaza\Productslider\Block\Adminhtml\Slider\Edit\Tab\Renderer\Responsive', [
135-
'name' => 'responsive_items',
136-
'label' => __('Max Items slider'),
137-
'title' => __('Max Items slider'),
138-
]);
135+
$responsiveItem = $fieldset->addField(
136+
'responsive_items',
137+
'Mageplaza\Productslider\Block\Adminhtml\Slider\Edit\Tab\Renderer\Responsive',
138+
[
139+
'name' => 'responsive_items',
140+
'label' => __('Max Items slider'),
141+
'title' => __('Max Items slider'),
142+
]
143+
);
139144

140145
$this->setChild(
141146
'form_after',

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class Products extends Extended implements TabInterface
5757

5858
/**
5959
* Products constructor.
60+
*
6061
* @param HeplerData $helperData
6162
* @param Context $context
6263
* @param Data $backendHelper
@@ -72,8 +73,8 @@ public function __construct(
7273
CollectionFactory $productCollectionFactory,
7374
array $data = []
7475
) {
75-
$this->_helperData = $helperData;
76-
$this->_sliderFactory = $sliderFactory;
76+
$this->_helperData = $helperData;
77+
$this->_sliderFactory = $sliderFactory;
7778
$this->_productCollectionFactory = $productCollectionFactory;
7879

7980
parent::__construct($context, $backendHelper, $data);
@@ -179,6 +180,7 @@ public function getGridUrl()
179180

180181
/**
181182
* @param object $row
183+
*
182184
* @return string
183185
*/
184186
public function getRowUrl($row)
@@ -188,6 +190,7 @@ public function getRowUrl($row)
188190

189191
/**
190192
* @param Column $column
193+
*
191194
* @return $this
192195
* @throws LocalizedException
193196
* @throws Zend_Serializer_Exception
@@ -219,7 +222,7 @@ protected function _addColumnFilterToCollection($column)
219222
*/
220223
protected function _getSelectedProducts()
221224
{
222-
$slider = $this->getSlider();
225+
$slider = $this->getSlider();
223226
$productIds = $slider->getProductIds() ? explode('&', $slider->getProductIds()) : [];
224227

225228
return $productIds;
@@ -231,7 +234,7 @@ protected function _getSelectedProducts()
231234
protected function getSlider()
232235
{
233236
$sliderId = $this->getRequest()->getParam('id');
234-
$slider = $this->_sliderFactory->create();
237+
$slider = $this->_sliderFactory->create();
235238
if ($sliderId) {
236239
$slider->load($sliderId);
237240
}
@@ -244,7 +247,7 @@ protected function getSlider()
244247
*/
245248
public function getSelectedProducts()
246249
{
247-
$slider = $this->getSlider();
250+
$slider = $this->getSlider();
248251
$selected = $slider->getProductIds() ? explode('&', $slider->getProductIds()) : [];
249252

250253
if (!is_array($selected)) {

Block/Adminhtml/Slider/Edit/Tab/Renderer/Category.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class Category extends Multiselect
6060

6161
/**
6262
* Category constructor.
63+
*
6364
* @param Options $options
6465
* @param Factory $factoryElement
6566
* @param CollectionFactory $factoryCollection
@@ -79,10 +80,10 @@ public function __construct(
7980
UrlInterface $urlBuilder,
8081
array $data = []
8182
) {
82-
$this->_option = $options;
83+
$this->_option = $options;
8384
$this->collectionFactory = $collectionFactory;
84-
$this->authorization = $authorization;
85-
$this->_urlBuilder = $urlBuilder;
85+
$this->authorization = $authorization;
86+
$this->_urlBuilder = $urlBuilder;
8687

8788
parent::__construct($factoryElement, $factoryCollection, $escaper, $data);
8889
}
@@ -204,7 +205,7 @@ public function getNoDisplay()
204205
public function getCategoriesTree()
205206
{
206207
/* @var $collection Collection */
207-
$collection = $this->collectionFactory->create();
208+
$collection = $this->collectionFactory->create();
208209
$categoryById = [
209210
CategoryModel::TREE_ROOT_ID => [
210211
'value' => CategoryModel::TREE_ROOT_ID,
@@ -219,8 +220,8 @@ public function getCategoriesTree()
219220
}
220221
}
221222

222-
$categoryById[$category->getId()]['is_active'] = 1;
223-
$categoryById[$category->getId()]['label'] = $category->getName();
223+
$categoryById[$category->getId()]['is_active'] = 1;
224+
$categoryById[$category->getId()]['label'] = $category->getName();
224225
$categoryById[$category->getParentId()]['optgroup'][] = &$categoryById[$category->getId()];
225226
}
226227

Block/Adminhtml/Slider/Edit/Tab/Renderer/Responsive.php

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Responsive extends AbstractElement
4040

4141
/**
4242
* Responsive constructor.
43+
*
4344
* @param Factory $factoryElement
4445
* @param CollectionFactory $factoryCollection
4546
* @param Escaper $escaper

Block/BestSellerProducts.php

+22-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
2727
use Magento\Framework\App\Http\Context as HttpContext;
2828
use Magento\Framework\Stdlib\DateTime\DateTime;
29+
use Magento\Framework\Url\EncoderInterface;
2930
use Magento\Sales\Model\ResourceModel\Report\Bestsellers\CollectionFactory as BestSellersCollectionFactory;
3031
use Mageplaza\Productslider\Helper\Data;
3132

@@ -42,12 +43,14 @@ class BestSellerProducts extends AbstractSlider
4243

4344
/**
4445
* BestSellerProducts constructor.
46+
*
4547
* @param Context $context
4648
* @param CollectionFactory $productCollectionFactory
4749
* @param Visibility $catalogProductVisibility
4850
* @param DateTime $dateTime
4951
* @param Data $helperData
5052
* @param HttpContext $httpContext
53+
* @param EncoderInterface $urlEncoder
5154
* @param BestSellersCollectionFactory $bestSellersCollectionFactory
5255
* @param array $data
5356
*/
@@ -58,12 +61,22 @@ public function __construct(
5861
DateTime $dateTime,
5962
Data $helperData,
6063
HttpContext $httpContext,
64+
EncoderInterface $urlEncoder,
6165
BestSellersCollectionFactory $bestSellersCollectionFactory,
6266
array $data = []
6367
) {
6468
$this->_bestSellersCollectionFactory = $bestSellersCollectionFactory;
6569

66-
parent::__construct($context, $productCollectionFactory, $catalogProductVisibility, $dateTime, $helperData, $httpContext, $data);
70+
parent::__construct(
71+
$context,
72+
$productCollectionFactory,
73+
$catalogProductVisibility,
74+
$dateTime,
75+
$helperData,
76+
$httpContext,
77+
$urlEncoder,
78+
$data
79+
);
6780
}
6881

6982
/**
@@ -72,8 +85,10 @@ public function __construct(
7285
*/
7386
public function getProductCollection()
7487
{
75-
$productIds = [];
88+
$productIds = [];
7689
$bestSellers = $this->_bestSellersCollectionFactory->create()
90+
->setModel('Magento\Catalog\Model\Product')
91+
->addStoreFilter($this->getStoreId())
7792
->setPeriod('month');
7893

7994
foreach ($bestSellers as $product) {
@@ -84,8 +99,11 @@ public function getProductCollection()
8499
$collection->addMinimalPrice()
85100
->addFinalPrice()
86101
->addTaxPercents()
87-
->addAttributeToSelect('*')
88-
->addStoreFilter($this->getStoreId())->setPageSize($this->getProductsCount());
102+
->addAttributeToSelect($this->_catalogConfig->getProductAttributes())
103+
->addStoreFilter($this->getStoreId())
104+
->addUrlRewrite()
105+
->setVisibility($this->_catalogProductVisibility->getVisibleInSiteIds())
106+
->setPageSize($this->getProductsCount());
89107

90108
return $collection;
91109
}

0 commit comments

Comments
 (0)