Skip to content

Commit 322b5dd

Browse files
authored
Merge pull request #1 from landofcoder/develop
Develop
2 parents 9d70bf7 + c86fcfe commit 322b5dd

35 files changed

+1803
-257
lines changed

Block/Adminhtml/Designer/Edit/Tab/Main.php

Lines changed: 157 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,25 @@ class Main extends \Magento\Backend\Block\Widget\Form\Generic implements \Magent
3737
*/
3838
protected $_viewHelper;
3939

40+
/**
41+
* @var \Magento\Directory\Model\Config\Source\Country
42+
*/
43+
protected $_country;
44+
45+
/**
46+
* @var \Magento\Directory\Model\RegionFactory
47+
*/
48+
protected $_regionFactory;
49+
4050
/**
4151
* @param \Magento\Backend\Block\Template\Context $context
4252
* @param \Magento\Framework\Registry $registry
4353
* @param \Magento\Framework\Data\FormFactory $formFactory
4454
* @param \Magento\Store\Model\System\Store $systemStore
4555
* @param \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig
46-
* @param \Lof\Designer\Helper\Data $viewHelper
56+
* @param \Lof\Designer\Helper\Data $viewHelper
57+
* @param \Magento\Directory\Model\Config\Source\Country $country
58+
* @param \Magento\Directory\Model\RegionFactory $regionFactory
4759
* @param array $data
4860
*/
4961
public function __construct(
@@ -53,11 +65,15 @@ public function __construct(
5365
\Magento\Store\Model\System\Store $systemStore,
5466
\Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig,
5567
\Lof\Designer\Helper\Data $viewHelper,
68+
\Magento\Directory\Model\Config\Source\Country $country,
69+
\Magento\Directory\Model\RegionFactory $regionFactory,
5670
array $data = []
5771
) {
5872
$this->_viewHelper = $viewHelper;
5973
$this->_systemStore = $systemStore;
6074
$this->_wysiwygConfig = $wysiwygConfig;
75+
$this->_country = $country;
76+
$this->_regionFactory = $regionFactory;
6177
parent::__construct($context, $registry, $formFactory, $data);
6278
}
6379

@@ -70,8 +86,13 @@ public function __construct(
7086
protected function _prepareForm() {
7187
/** @var $model \Lof\Designer\Model\Designer */
7288
$model = $this->_coreRegistry->registry('lof_designer');
73-
89+
$formData = array('country_id' => "");
7490
$wysiwygConfig = $this->_wysiwygConfig->getConfig(['tab_id' => $this->getTabId()]);
91+
$countries = $this->_country->toOptionArray(false, 'US');
92+
$regionCollection = $this->_regionFactory->create()->getCollection()->addCountryFilter(
93+
$formData['country_id']
94+
);
95+
$regions = $regionCollection->toOptionArray();
7596
/**
7697
* Checking if user have permission to save information
7798
*/
@@ -192,8 +213,142 @@ protected function _prepareForm() {
192213
);
193214
$model->setStoreId($this->_storeManager->getStore(true)->getId());
194215
}
216+
$fieldset->addField(
217+
'birthday_info',
218+
'text',
219+
[
220+
'name' => 'birthday_info',
221+
'label' => __('Birthday Info'),
222+
'title' => __('Birthday Info'),
223+
'disabled' => $isElementDisabled
224+
]
225+
);
226+
$fieldset->addField(
227+
'contact_name',
228+
'text',
229+
[
230+
'name' => 'contact_name',
231+
'label' => __('Contact Name'),
232+
'title' => __('Contact Name'),
233+
'disabled' => $isElementDisabled
234+
]
235+
);
195236

237+
$fieldset->addField(
238+
'company_name',
239+
'text',
240+
[
241+
'name' => 'company_name',
242+
'label' => __('Company Name'),
243+
'title' => __('Company Name'),
244+
'disabled' => $isElementDisabled
245+
]
246+
);
247+
248+
$fieldset->addField(
249+
'email',
250+
'text',
251+
[
252+
'name' => 'email',
253+
'label' => __('Email'),
254+
'title' => __('Email'),
255+
'disabled' => $isElementDisabled
256+
]
257+
);
258+
259+
$fieldset->addField(
260+
'telephone',
261+
'text',
262+
[
263+
'name' => 'telephone',
264+
'label' => __('Telephone'),
265+
'title' => __('Telephone'),
266+
'disabled' => $isElementDisabled
267+
]
268+
);
196269

270+
$fieldset->addField(
271+
'street',
272+
'text',
273+
[
274+
'name' => 'street',
275+
'label' => __('Street'),
276+
'title' => __('Street'),
277+
'disabled' => $isElementDisabled
278+
]
279+
);
280+
281+
$fieldset->addField(
282+
'website',
283+
'text',
284+
[
285+
'name' => 'website',
286+
'label' => __('Website'),
287+
'title' => __('Website'),
288+
'disabled' => $isElementDisabled
289+
]
290+
);
291+
$fieldset->addField(
292+
'country_id',
293+
'select',
294+
[
295+
'name' => 'country_id',
296+
'label' => __('Country'),
297+
'title' => __('Country'),
298+
'values' => $countries,
299+
'disabled' => $isElementDisabled
300+
]
301+
);
302+
303+
$fieldset->addField(
304+
'region_id',
305+
'select',
306+
[
307+
'name' => 'region_id',
308+
'label' => __('State'),
309+
'title' => __('State'),
310+
'values' => $regions,
311+
'disabled' => $isElementDisabled
312+
]
313+
);
314+
315+
$fieldset->addField(
316+
'region',
317+
'text',
318+
[
319+
'name' => 'region',
320+
'label' => __('Region'),
321+
'title' => __('Region'),
322+
'disabled' => $isElementDisabled
323+
]
324+
);
325+
326+
$fieldset->addField(
327+
'city',
328+
'text',
329+
[
330+
'name' => 'city',
331+
'label' => __('City'),
332+
'title' => __('City'),
333+
'disabled' => $isElementDisabled
334+
]
335+
);
336+
337+
$fieldset->addField(
338+
'postcode',
339+
'text',
340+
[
341+
'name' => 'postcode',
342+
'label' => __('Postcode'),
343+
'title' => __('Postcode'),
344+
'disabled' => $isElementDisabled
345+
]
346+
);
347+
$this->setChild(
348+
'form_after',
349+
$this->getLayout()->createBlock('Magento\Framework\View\Element\Template')->setTemplate('Lof_Designer::country/js.phtml')
350+
);
351+
197352
$fieldset->addField(
198353
'position',
199354
'text',

Block/Designerpage.php

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class Designerpage extends \Magento\Framework\View\Element\Template
3939
*/
4040
protected $_designer;
4141

42+
protected $_collection = null;
43+
44+
4245
/**
4346
* @param \Magento\Framework\View\Element\Template\Context $context
4447
* @param \Magento\Framework\Registry $registry
@@ -52,6 +55,7 @@ public function __construct(
5255
\Magento\Framework\Registry $registry,
5356
\Lof\Designer\Helper\Data $designerHelper,
5457
\Lof\Designer\Model\Designer $designer,
58+
5559
array $data = []
5660
) {
5761
$this->_designer = $designer;
@@ -64,20 +68,14 @@ public function _construct()
6468
{
6569
if(!$this->getConfig('general_settings/enable')) return;
6670
parent::_construct();
67-
68-
$store = $this->_storeManager->getStore();
69-
$itemsperpage = (int)$this->getConfig('designer_list_page/item_per_page',12);
70-
$designer = $this->_designer;
71-
$designerCollection = $designer->getCollection()
72-
->addFieldToFilter('status',1)
73-
->addStoreFilter($store)
74-
->setOrder('position','ASC');
75-
$this->setCollection($designerCollection);
76-
7771
$template = '';
7872
$layout = $this->getConfig('designer_list_page/layout');
7973
if($layout == 'grid'){
8074
$template = 'designerlistpage_grid.phtml';
75+
}elseif($layout == 'alphabet'){
76+
$template = 'designerlistpage_alphabet.phtml';
77+
}elseif($layout == 'newlist'){
78+
$template = 'designerlistpage_newlist.phtml';
8179
}else{
8280
$template = 'designerlistpage_list.phtml';
8381
}
@@ -97,7 +95,6 @@ protected function _addBreadcrumbs()
9795
{
9896
$breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs');
9997
$baseUrl = $this->_storeManager->getStore()->getBaseUrl();
100-
$designerRoute = $this->_designerHelper->getConfig('general_settings/route');
10198
$page_title = $this->_designerHelper->getConfig('designer_list_page/page_title');
10299

103100
if($breadcrumbsBlock){
@@ -137,8 +134,20 @@ public function setCollection($collection)
137134
*/
138135
public function getCollection()
139136
{
140-
$this->_collection->getSelect()->reset(\Magento\Framework\DB\Select::ORDER);
141-
$this->_collection->setOrder('position','ASC');
137+
if($this->_collection == null){
138+
$store = $this->_storeManager->getStore();
139+
140+
$designer = $this->_designer;
141+
$designerCollection = $designer->getCollection()
142+
->addFieldToFilter('status',1)
143+
->addStoreFilter($store)
144+
->setOrder('position','ASC');
145+
146+
$designerCollection->getSelect()->reset(\Zend_Db_Select::ORDER);
147+
$designerCollection->setOrder('position','ASC');
148+
$this->setCollection($designerCollection);
149+
150+
}
142151
return $this->_collection;
143152
}
144153

@@ -200,13 +209,55 @@ protected function _beforeToHtml()
200209
{
201210
$collection = $this->getCollection();
202211
$toolbar = $this->getToolbarBlock();
203-
212+
$pretext = $this->getConfig('designer_list_page/pretext');
213+
if($pretext){
214+
$pretext = $this->_designerHelper->filter($pretext);
215+
}
216+
$this->setData("pretext", $pretext);
217+
204218
// set collection to toolbar and apply sort
219+
$itemsperpage = (int)$this->getConfig('designer_list_page/item_per_page',0);
220+
if(!$itemsperpage) {
221+
$toolbar = false;
222+
}
205223
if($toolbar){
206-
$itemsperpage = (int)$this->getConfig('designer_list_page/item_per_page',12);
207224
$toolbar->setData('_current_limit',$itemsperpage)->setCollection($collection);
208225
$this->setChild('toolbar', $toolbar);
209226
}
227+
$layout = $this->getConfig('designer_list_page/layout');
228+
if($layout == 'alphabet'){
229+
$collection = $this->sortDesignerByAlphabet($collection);
230+
$this->setCollection($collection);
231+
}
210232
return parent::_beforeToHtml();
211233
}
234+
235+
public function getAlphabetLetters(){
236+
$alphabet = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
237+
return $alphabet;
238+
}
239+
240+
public function sortDesignerByAlphabet($collection = null){
241+
if(!$collection){
242+
$collection = $this->getCollection();
243+
}
244+
$letters = $this->getAlphabetLetters();
245+
$output = array();
246+
foreach($letters as $letter){
247+
$output[$letter] = array();
248+
}
249+
$output["#"] = array();
250+
251+
foreach($collection as $_designer) {
252+
$designer_name = $_designer->getName();
253+
$letter = strtoupper(substr($designer_name, 0, 1));
254+
if(!in_array($letter,$letters)){
255+
$letter = "#";
256+
}
257+
$total_products = $_designer->getTotalProducts();
258+
$output[ $letter ][] = $_designer; // Or, whatever you want to output.
259+
260+
}
261+
return $output;
262+
}
212263
}

0 commit comments

Comments
 (0)