diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..003c634 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +*.zip +.DS_Store \ No newline at end of file diff --git a/README.md b/README.md new file mode 100755 index 0000000..6b3f86f --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# Sort By Date for Magento® 1 + +Sort your product listing by date to show the newest product first. + +## Development by Magmodules + +We are a Dutch Magento® Only Agency dedicated to the development of extensions for Magento® 1 and Magento® 2. All our extensions are coded by our own team and our support team is always there to help you out. + +## Links + +[Visit Magmodules.eu](https://www.magmodules.eu/) + +[Terms and Conditions](https://www.magmodules.eu/terms.html) + +[Contact Us](https://www.magmodules.eu/contact-us.html) \ No newline at end of file diff --git a/app/code/local/Magmodules/Sortbydate/Block/Adminhtml/Render/Button.php b/app/code/local/Magmodules/Sortbydate/Block/Adminhtml/Render/Button.php new file mode 100755 index 0000000..d61b907 --- /dev/null +++ b/app/code/local/Magmodules/Sortbydate/Block/Adminhtml/Render/Button.php @@ -0,0 +1,60 @@ + + * @copyright Copyright (c) 2017 (http://www.magmodules.eu) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ + +class Magmodules_Sortbydate_Block_Adminhtml_Render_Button extends Mage_Adminhtml_Block_System_Config_Form_Field +{ + + /** + * @param Varien_Data_Form_Element_Abstract $element + * + * @return mixed + */ + protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) + { + + $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute(); + $attributeId = $eavAttribute->getIdByCode('catalog_product', 'created_at'); + + if ($attributeId) { + $attributeModel = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'created_at'); + $sort = $attributeModel['used_for_sort_by']; + if ($sort) { + $url = $this->getUrl('*/updatesort/index'); + $title = Mage::helper('sortbydate')->__('Remove as listing option'); + } else { + $url = $this->getUrl('*/updatesort/index'); + $title = Mage::helper('sortbydate')->__('Add as listing option'); + } + } else { + $url = $this->getUrl('*/updatesort/index'); + $title = Mage::helper('sortbydate')->__('Add as listing option'); + } + + $this->setElement($element); + $html = $this->getLayout()->createBlock('adminhtml/widget_button') + ->setType('button') + ->setClass('scalable') + ->setLabel($title) + ->setOnClick("setLocation('$url')") + ->toHtml(); + + return $html; + } +} \ No newline at end of file diff --git a/app/code/local/Magmodules/Sortbydate/Block/Adminhtml/Render/Status.php b/app/code/local/Magmodules/Sortbydate/Block/Adminhtml/Render/Status.php new file mode 100755 index 0000000..eab45b4 --- /dev/null +++ b/app/code/local/Magmodules/Sortbydate/Block/Adminhtml/Render/Status.php @@ -0,0 +1,49 @@ + + * @copyright Copyright (c) 2017 (http://www.magmodules.eu) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ + +class Magmodules_Sortbydate_Block_Adminhtml_Render_Status extends Mage_Adminhtml_Block_System_Config_Form_Field +{ + + /** + * @param Varien_Data_Form_Element_Abstract $element + * + * @return string + */ + protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) + { + + $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute(); + $attributeId = $eavAttribute->getIdByCode('catalog_product', 'created_at'); + + if ($attributeId) { + $attributeModel = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'created_at'); + $sort = $attributeModel['used_for_sort_by']; + if ($sort) { + $html = '' . Mage::helper('sortbydate')->__('Installed!') . ''; + } else { + $html = '' . Mage::helper('sortbydate')->__('Not Installed') . ''; + } + } else { + $html = '' . Mage::helper('sortbydate')->__('Not Installed') . ''; + } + return $html; + } + +} \ No newline at end of file diff --git a/app/code/local/Magmodules/Sortbydate/Helper/Data.php b/app/code/local/Magmodules/Sortbydate/Helper/Data.php new file mode 100755 index 0000000..4739672 --- /dev/null +++ b/app/code/local/Magmodules/Sortbydate/Helper/Data.php @@ -0,0 +1,24 @@ + + * @copyright Copyright (c) 2017 (http://www.magmodules.eu) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ + +class Magmodules_Sortbydate_Helper_Data extends Mage_Core_Helper_Abstract +{ + +} \ No newline at end of file diff --git a/app/code/local/Magmodules/Sortbydate/Model/System/Config/Source/Sorting.php b/app/code/local/Magmodules/Sortbydate/Model/System/Config/Source/Sorting.php new file mode 100755 index 0000000..8ab47aa --- /dev/null +++ b/app/code/local/Magmodules/Sortbydate/Model/System/Config/Source/Sorting.php @@ -0,0 +1,34 @@ + + * @copyright Copyright (c) 2017 (http://www.magmodules.eu) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ + +class Magmodules_Sortbydate_Model_System_Config_Source_Sorting +{ + + /** + * @return array + */ + public function toOptionArray() + { + $sorting = array(); + $sorting[] = array('value' => '', 'label' => Mage::helper('sortbydate')->__('Default')); + $sorting[] = array('value' => '1', 'label' => Mage::helper('sortbydate')->__('Newest First')); + return $sorting; + } +} \ No newline at end of file diff --git a/app/code/local/Magmodules/Sortbydate/controllers/Adminhtml/UpdatesortController.php b/app/code/local/Magmodules/Sortbydate/controllers/Adminhtml/UpdatesortController.php new file mode 100755 index 0000000..00f0b60 --- /dev/null +++ b/app/code/local/Magmodules/Sortbydate/controllers/Adminhtml/UpdatesortController.php @@ -0,0 +1,58 @@ + + * @copyright Copyright (c) 2017 (http://www.magmodules.eu) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ + +class Magmodules_Sortbydate_Adminhtml_UpdatesortController extends Mage_Adminhtml_Controller_Action +{ + + /** + * + */ + public function indexAction() + { + $eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute(); + $attributeId = $eavAttribute->getIdByCode('catalog_product', 'created_at'); + + if($attributeId) { + $attributeModel = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'created_at'); + $sort = $attributeModel['used_for_sort_by']; + if($sort) { + $attributeModel->setUsedForSortBy(0); + $attributeModel->save(); + Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('sortbydate')->__('Sort by date has been removed as listing option')); + } else { + $attributeModel->setUsedForSortBy(1); + $attributeModel->save(); + Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('sortbydate')->__('Sort by date has been added to the listing options')); + } + } else { + Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('sortbydate')->__('Sort by date has been added to the listing options')); + } + + $this->_redirect('adminhtml/system_config/edit/section/sortbydate'); + } + + /** + * @return mixed + */ + protected function _isAllowed() + { + return true; + } +} \ No newline at end of file diff --git a/app/code/local/Magmodules/Sortbydate/etc/adminhtml.xml b/app/code/local/Magmodules/Sortbydate/etc/adminhtml.xml new file mode 100755 index 0000000..2ae3cf1 --- /dev/null +++ b/app/code/local/Magmodules/Sortbydate/etc/adminhtml.xml @@ -0,0 +1,50 @@ + + + + + + + + + Sort By Date + -100 + + + Index Action + 1 + + + + + + + + + Sort by Date + + + + + + + + + + \ No newline at end of file diff --git a/app/code/local/Magmodules/Sortbydate/etc/config.xml b/app/code/local/Magmodules/Sortbydate/etc/config.xml new file mode 100755 index 0000000..853d96e --- /dev/null +++ b/app/code/local/Magmodules/Sortbydate/etc/config.xml @@ -0,0 +1,83 @@ + + + + + + 1.5.0 + + + + + + Magmodules_Sortbydate_Helper + + + + + Magmodules_Sortbydate_Model + + + + + Magmodules_Sortbydate_Block + + + + + + Magmodules_Sortbydate + Mage_Catalog_Model_Resource_Eav_Mysql4_Setup + + + core_setup + + + + + + + + + + Magmodules_Sortbydate.csv + + + + + + + + magmodules_sortbydate.xml + + + + + + + + + + Magmodules_Sortbydate_Adminhtml + + + + + + \ No newline at end of file diff --git a/app/code/local/Magmodules/Sortbydate/etc/system.xml b/app/code/local/Magmodules/Sortbydate/etc/system.xml new file mode 100755 index 0000000..aeb8392 --- /dev/null +++ b/app/code/local/Magmodules/Sortbydate/etc/system.xml @@ -0,0 +1,87 @@ + + + + + + + 200 + + + + + + magmodules + mm-moduleheader + text + 119 + 1 + 1 + 1 + + + + text + 1 + 1 + 1 + 1 + 1 + + + Need help with this extension? + Please visit magmodules.eu/help/sort-by-date for tips and tricks. +

+ ]]> +
+ + + + select + sortbydate/system_config_source_sorting + 1 + 1 + 1 + 1 + + + + text + sortbydate/adminhtml_render_status + 2 + 1 + 1 + 1 + + + + button + sortbydate/adminhtml_render_button + 3 + 1 + 1 + 1 + + +
+
+
+
+
\ No newline at end of file diff --git a/app/code/local/Magmodules/Sortbydate/sql/sortbydate_setup/mysql4-install-0.1.0.php b/app/code/local/Magmodules/Sortbydate/sql/sortbydate_setup/mysql4-install-0.1.0.php new file mode 100755 index 0000000..902622c --- /dev/null +++ b/app/code/local/Magmodules/Sortbydate/sql/sortbydate_setup/mysql4-install-0.1.0.php @@ -0,0 +1,26 @@ + + * @copyright Copyright (c) 2017 (http://www.magmodules.eu) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ + +$installer = $this; +$installer->startSetup(); +$prodEntityTypeId = $installer->getEntityTypeId('catalog_product'); +$installer->updateAttribute($prodEntityTypeId, 'created_at', 'frontend_label', 'Date'); +$installer->updateAttribute($prodEntityTypeId, 'created_at', 'used_for_sort_by', 1); +$installer->endSetup(); \ No newline at end of file diff --git a/app/design/frontend/base/default/layout/magmodules_sortbydate.xml b/app/design/frontend/base/default/layout/magmodules_sortbydate.xml new file mode 100755 index 0000000..31180a7 --- /dev/null +++ b/app/design/frontend/base/default/layout/magmodules_sortbydate.xml @@ -0,0 +1,35 @@ + + + + + + + desc + + + + + + + desc + + + + \ No newline at end of file diff --git a/app/etc/modules/Magmodules_Sortbydate.xml b/app/etc/modules/Magmodules_Sortbydate.xml new file mode 100755 index 0000000..620d313 --- /dev/null +++ b/app/etc/modules/Magmodules_Sortbydate.xml @@ -0,0 +1,27 @@ + + + + + + true + local + + + \ No newline at end of file diff --git a/app/locale/en_US/Magmodules_Sortbydate.csv b/app/locale/en_US/Magmodules_Sortbydate.csv new file mode 100755 index 0000000..f8997d6 --- /dev/null +++ b/app/locale/en_US/Magmodules_Sortbydate.csv @@ -0,0 +1 @@ +"Created at", "Newest" \ No newline at end of file diff --git a/app/locale/nl_NL/Magmodules_Sortbydate.csv b/app/locale/nl_NL/Magmodules_Sortbydate.csv new file mode 100755 index 0000000..2dcd100 --- /dev/null +++ b/app/locale/nl_NL/Magmodules_Sortbydate.csv @@ -0,0 +1 @@ +"Created at", "Datum" \ No newline at end of file diff --git a/modman b/modman new file mode 100755 index 0000000..7cf9f13 --- /dev/null +++ b/modman @@ -0,0 +1,5 @@ +app/code/local/Magmodules/Sortbydate app/code/local/Magmodules/Sortbydate +app/etc/modules/Magmodules_Sortbydate.xml app/etc/modules/Magmodules_Sortbydate.xml +app/locale/en_US/Magmodules_Sortbydate.csv app/locale/en_US/Magmodules_Sortbydate.csv +app/locale/nl_NL/Magmodules_Sortbydate.csv app/locale/nl_NL/Magmodules_Sortbydate.csv +app/design/frontend/base/default/layout/magmodules_sortbydate.xml app/design/frontend/base/default/layout/magmodules_sortbydate.xml