Featured post

Magento® 2.x How to create basic frontend module

How to create basic frontend module in Magneto 2 ?? Step 1. Decide a name space(Extendtree) & module name(Helloworld). Ex. Extendtre...

Showing posts with label Magento- An Ecommerce Framework. Show all posts
Showing posts with label Magento- An Ecommerce Framework. Show all posts

Saturday, 3 September 2016

Magento1.x ® System Configuration -How to create simple configuration settings.


How to create Magneto System Configuration Settings??

  • Step 1. Create global configuration File
  • Step 2. Create module configuration file
  • Step 3. Create helper class
  • Step 4. Create System configuration file

Step 1. Each Module should have one Namespace & Module name. Name space could be some company name etc. & module name should be something that represents module functionality. So let suppose Namespace is ExtendTree and Module name is ConfigurationSettings. Now Create Global Configuration File inside root directory /app/etc/modules as name "ExtendTree_ConfigurationSettings.xml"

<!--xml version="1.0" encoding="UTF-8"?--> <config> <modules> <ExtendTree_ConfigurationSettings> <active>true</active> <codePool>local</codePool> </ExtendTree_ConfigurationSettings> </modules> </config>

Step 2. Now Create Module Configuration File inside the directory /app/code/local/ExtendTree/ConfigurationSettings/etc as name "config.xml"

<config> <modules> <ExtendTree_ConfigurationSettings> <version>0.0.1</version> </ExtendTree_ConfigurationSettings> </modules> <adminhtml> <acl> <resources> <all> <title>Allow Everything</title> </all> <admin> <children> <system> <children> <config> <children> <extendtree> <title>ExtendTree</title> </extendtree> </children> </config> </children> </system> </children> </admin> </resources> </acl> </adminhtml> <global> <helpers> <configurationSettings> <class>ExtendTree_ConfigurationSettings_Helper</class> </configurationSettings> </helpers> </global> </config>

Step 3. Now next thing is to create helper inside the directory /app/code/local/ExtendTree/ConfigurationSettings/Helper/ as name "Data.php"

class ExtendTree_ConfigurationSettings_Helper_Data extends Mage_Core_Helper_Abstract { }

Step 4. Now last thing is to create system configuration file inside the directory /app/code/local/ExtendTree/ConfigurationSettings/etc/ as name "System.xml"

<config> <tabs> <extendtree translate="label" module="configurationSettings"> <label>ExtendTree</label> <sort_order>0</sort_order> </extendtree> </tabs> <sections> <extendtree translate="label" module="configurationSettings"> <label>ExtendTree Section</label> <tab>extendtree</tab> <frontend_type>text</frontend_type> <sort_order>40</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> <groups> <extendtree_groups translate="label"> <label>ExtendTree Group</label> <frontend_type>text</frontend_type> <sort_order>100</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> <fields> <extendtree_field1 translate="label"> <label>Test Field 1</label> <comment><!--[CDATA[This is Text Field 1]]--> </comment> <frontend_type>text</frontend_type> <sort_order>1</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> </extendtree_field1> <extendtree_field2 translate="label"> <label>Test Field 2</label> <comment><!--[CDATA[This is Text Field 2]]--> </comment> <frontend_type>select</frontend_type> <source_model>adminhtml/system_config_source_yesno</source_model> <sort_order>2</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> </extendtree_field2> <extendtree_field3 translate="label"> <label>Test Field 3</label> <comment><!--[CDATA[This is Text Field 3]]--> </comment> <frontend_type>textarea</frontend_type> <sort_order>3</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> </extendtree_field3> </fields> </extendtree_groups> </groups> </extendtree> </sections> </config>

That's it..!! Now go toAdmin->System->Configuration. Here you should see the tab as "ExtendTree"

Thank you..!!

"The easy way for everything."

Magento 1.x ® Routers Override- How to override controllers


How to override Magneto controllers??

  • Step 1. Create global configuration File
  • Step 2. Create module configuration file
  • Step 3. Create new frontend controller
  • Step 4. Create new backend controller

Step 1. Each Module should have one Namespace & Module name. Name space could be some company name etc. & module name should be something that represents module functionality. So let suppose Namespace is ExtendTree and Module name is OverrideControllers. Now Create Global Configuration File inside root directory /app/etc/modules as name "ExtendTree_OverrideControllers.xml"

<!--xml version="1.0" encoding="UTF-8"?--> <config> <modules> <ExtendTree_OverrideControllers> <active>true</active> <codePool>local</codePool> </ExtendTree_OverrideControllers> </modules> </config>

Step 2. Now Create Module Configuration File inside the directory /app/code/local/ExtendTree/OverrideControllers/etc as name "config.xml"

<!--xml version="1.0"?--> <config> <modules> <ExtendTree_OverrideControllers> <version>0.0.1</version> </ExtendTree_OverrideControllers> </modules> <frontend> <routers> <checkout> <args> <modules> <extendTree_overrideControllers before="Mage_Checkout">ExtendTree_OverrideControllers</extendTree_overrideControllers> </modules> </args> </checkout> </routers> </frontend> <admin> <routers> <adminhtml> <args> <modules> <extendTree_overrideControllers before="Mage_Adminhtml">ExtendTree_OverrideControllers_Adminhtml</extendTree_overrideControllers> </modules> </args> </adminhtml> </routers> </admin> </config>

Step 3. Now create new frontend controller. Suppose we want to override frontend controller Mage_Checkout_OnepageController then we will create one controller class in our module in directory app/code/local/ExtendTree/OverrideControllers/controllers/ by name OnepageController.php

require_once(Mage::getModuleDir('controllers','Mage_Checkout').DS.'OnepageController.php'); class ExtendTree_OverrideControllers_OnepageController extends Mage_Checkout_OnepageController { /** * List of functions for section update * * @var array */ protected $_sectionUpdateFunctions = array( 'payment-method' => '_getPaymentMethodsHtml', 'shipping-method' => '_getShippingMethodsHtml', 'review' => '_getReviewHtml', ); /** * @var Mage_Sales_Model_Order */ protected $_order; /** * Predispatch: should set layout area * * @return Mage_Checkout_OnepageController */ public function preDispatch() { parent::preDispatch(); $this->_preDispatchValidateCustomer(); $checkoutSessionQuote = Mage::getSingleton('checkout/session')->getQuote(); if ($checkoutSessionQuote->getIsMultiShipping()) { $checkoutSessionQuote->setIsMultiShipping(false); $checkoutSessionQuote->removeAllAddresses(); } if (!$this->_canShowForUnregisteredUsers()) { $this->norouteAction(); $this->setFlag('',self::FLAG_NO_DISPATCH,true); return; } return $this; } /** * Send Ajax redirect response * * @return Mage_Checkout_OnepageController */ protected function _ajaxRedirectResponse() { $this->getResponse() ->setHeader('HTTP/1.1', '403 Session Expired') ->setHeader('Login-Required', 'true') ->sendResponse(); return $this; } /** * Validate ajax request and redirect on failure * * @return bool */ protected function _expireAjax() { if (!$this->getOnepage()->getQuote()->hasItems() || $this->getOnepage()->getQuote()->getHasError() || $this->getOnepage()->getQuote()->getIsMultiShipping() ) { $this->_ajaxRedirectResponse(); return true; } $action = $this->getRequest()->getActionName(); if (Mage::getSingleton('checkout/session')->getCartWasUpdated(true) && !in_array($action, array('index', 'progress')) ) { $this->_ajaxRedirectResponse(); return true; } return false; } /** * Get shipping method step html * * @return string */ protected function _getShippingMethodsHtml() { $layout = $this->getLayout(); $update = $layout->getUpdate(); $update->load('checkout_onepage_shippingmethod'); $layout->generateXml(); $layout->generateBlocks(); $output = $layout->getOutput(); return $output; } /** * Get payment method step html * * @return string */ protected function _getPaymentMethodsHtml() { $layout = $this->getLayout(); $update = $layout->getUpdate(); $update->load('checkout_onepage_paymentmethod'); $layout->generateXml(); $layout->generateBlocks(); $output = $layout->getOutput(); return $output; } /** * Return block content from the 'checkout_onepage_additional' * This is the additional content for shipping method * * @return string */ protected function _getAdditionalHtml() { $layout = $this->getLayout(); $update = $layout->getUpdate(); $update->load('checkout_onepage_additional'); $layout->generateXml(); $layout->generateBlocks(); $output = $layout->getOutput(); Mage::getSingleton('core/translate_inline')->processResponseBody($output); return $output; } /** * Get order review step html * * @return string */ protected function _getReviewHtml() { return $this->getLayout()->getBlock('root')->toHtml(); } /** * Get one page checkout model * * @return Mage_Checkout_Model_Type_Onepage */ public function getOnepage() { return Mage::getSingleton('checkout/type_onepage'); } /** * Checkout page */ public function indexAction() { if (!Mage::helper('checkout')->canOnepageCheckout()) { Mage::getSingleton('checkout/session')->addError($this->__('The onepage checkout is disabled.')); $this->_redirect('checkout/cart'); return; } $quote = $this->getOnepage()->getQuote(); if (!$quote->hasItems() || $quote->getHasError()) { $this->_redirect('checkout/cart'); return; } if (!$quote->validateMinimumAmount()) { $error = Mage::getStoreConfig('sales/minimum_order/error_message') ? Mage::getStoreConfig('sales/minimum_order/error_message') : Mage::helper('checkout')->__('Subtotal must exceed minimum order amount'); Mage::getSingleton('checkout/session')->addError($error); $this->_redirect('checkout/cart'); return; } Mage::getSingleton('checkout/session')->setCartWasUpdated(false); Mage::getSingleton('customer/session')->setBeforeAuthUrl(Mage::getUrl('*/*/*', array('_secure' => true))); $this->getOnepage()->initCheckout(); $this->loadLayout(); $this->_initLayoutMessages('customer/session'); $this->getLayout()->getBlock('head')->setTitle($this->__('Checkout')); $this->renderLayout(); } /** * Refreshes the previous step * Loads the block corresponding to the current step and sets it * in to the response body * * This function is called from the reloadProgessBlock * function from the javascript * * @return string|null */ public function progressAction() { // previous step should never be null. We always start with billing and go forward $prevStep = $this->getRequest()->getParam('prevStep', false); if ($this->_expireAjax() || !$prevStep) { return null; } $layout = $this->getLayout(); $update = $layout->getUpdate(); /* Load the block belonging to the current step*/ $update->load('checkout_onepage_progress_' . $prevStep); $layout->generateXml(); $layout->generateBlocks(); $output = $layout->getOutput(); $this->getResponse()->setBody($output); return $output; } /** * Shipping method action */ public function shippingMethodAction() { if ($this->_expireAjax()) { return; } $this->loadLayout(false); $this->renderLayout(); } /** * Review page action */ public function reviewAction() { if ($this->_expireAjax()) { return; } $this->loadLayout(false); $this->renderLayout(); } /** * Order success action */ public function successAction() { $session = $this->getOnepage()->getCheckout(); if (!$session->getLastSuccessQuoteId()) { $this->_redirect('checkout/cart'); return; } $lastQuoteId = $session->getLastQuoteId(); $lastOrderId = $session->getLastOrderId(); $lastRecurringProfiles = $session->getLastRecurringProfileIds(); if (!$lastQuoteId || (!$lastOrderId && empty($lastRecurringProfiles))) { $this->_redirect('checkout/cart'); return; } $session->clear(); $this->loadLayout(); $this->_initLayoutMessages('checkout/session'); Mage::dispatchEvent('checkout_onepage_controller_success_action', array('order_ids' => array($lastOrderId))); $this->renderLayout(); } /** * Failure action */ public function failureAction() { $lastQuoteId = $this->getOnepage()->getCheckout()->getLastQuoteId(); $lastOrderId = $this->getOnepage()->getCheckout()->getLastOrderId(); if (!$lastQuoteId || !$lastOrderId) { $this->_redirect('checkout/cart'); return; } $this->loadLayout(); $this->renderLayout(); } /** * Get additional info action */ public function getAdditionalAction() { $this->getResponse()->setBody($this->_getAdditionalHtml()); } /** * Address JSON */ public function getAddressAction() { if ($this->_expireAjax()) { return; } $addressId = $this->getRequest()->getParam('address', false); if ($addressId) { $address = $this->getOnepage()->getAddress($addressId); if (Mage::getSingleton('customer/session')->getCustomer()->getId() == $address->getCustomerId()) { $this->getResponse()->setHeader('Content-type', 'application/x-json'); $this->getResponse()->setBody($address->toJson()); } else { $this->getResponse()->setHeader('HTTP/1.1','403 Forbidden'); } } } /** * Save checkout method */ public function saveMethodAction() { if ($this->_expireAjax()) { return; } if ($this->getRequest()->isPost()) { $method = $this->getRequest()->getPost('method'); $result = $this->getOnepage()->saveCheckoutMethod($method); $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); } } /** * Save checkout billing address */ public function saveBillingAction() { if ($this->_expireAjax()) { return; } if ($this->getRequest()->isPost()) { $data = $this->getRequest()->getPost('billing', array()); $customerAddressId = $this->getRequest()->getPost('billing_address_id', false); if (isset($data['email'])) { $data['email'] = trim($data['email']); } $result = $this->getOnepage()->saveBilling($data, $customerAddressId); if (!isset($result['error'])) { if ($this->getOnepage()->getQuote()->isVirtual()) { $result['goto_section'] = 'payment'; $result['update_section'] = array( 'name' => 'payment-method', 'html' => $this->_getPaymentMethodsHtml() ); } elseif (isset($data['use_for_shipping']) && $data['use_for_shipping'] == 1) { $result['goto_section'] = 'shipping_method'; $result['update_section'] = array( 'name' => 'shipping-method', 'html' => $this->_getShippingMethodsHtml() ); $result['allow_sections'] = array('shipping'); $result['duplicateBillingInfo'] = 'true'; } else { $result['goto_section'] = 'shipping'; } } $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); } } /** * Shipping address save action */ public function saveShippingAction() { if ($this->_expireAjax()) { return; } if ($this->getRequest()->isPost()) { $data = $this->getRequest()->getPost('shipping', array()); $customerAddressId = $this->getRequest()->getPost('shipping_address_id', false); $result = $this->getOnepage()->saveShipping($data, $customerAddressId); if (!isset($result['error'])) { $result['goto_section'] = 'shipping_method'; $result['update_section'] = array( 'name' => 'shipping-method', 'html' => $this->_getShippingMethodsHtml() ); } $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); } } /** * Shipping method save action */ public function saveShippingMethodAction() { if ($this->_expireAjax()) { return; } if ($this->getRequest()->isPost()) { $data = $this->getRequest()->getPost('shipping_method', ''); $result = $this->getOnepage()->saveShippingMethod($data); // $result will contain error data if shipping method is empty if (!$result) { Mage::dispatchEvent( 'checkout_controller_onepage_save_shipping_method', array( 'request' => $this->getRequest(), 'quote' => $this->getOnepage()->getQuote())); $this->getOnepage()->getQuote()->collectTotals(); $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); $result['goto_section'] = 'payment'; $result['update_section'] = array( 'name' => 'payment-method', 'html' => $this->_getPaymentMethodsHtml() ); } $this->getOnepage()->getQuote()->collectTotals()->save(); $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); } } /** * Save payment ajax action * * Sets either redirect or a JSON response */ public function savePaymentAction() { if ($this->_expireAjax()) { return; } try { if (!$this->getRequest()->isPost()) { $this->_ajaxRedirectResponse(); return; } $data = $this->getRequest()->getPost('payment', array()); $result = $this->getOnepage()->savePayment($data); // get section and redirect data $redirectUrl = $this->getOnepage()->getQuote()->getPayment()->getCheckoutRedirectUrl(); if (empty($result['error']) && !$redirectUrl) { $this->loadLayout('checkout_onepage_review'); $result['goto_section'] = 'review'; $result['update_section'] = array( 'name' => 'review', 'html' => $this->_getReviewHtml() ); } if ($redirectUrl) { $result['redirect'] = $redirectUrl; } } catch (Mage_Payment_Exception $e) { if ($e->getFields()) { $result['fields'] = $e->getFields(); } $result['error'] = $e->getMessage(); } catch (Mage_Core_Exception $e) { $result['error'] = $e->getMessage(); } catch (Exception $e) { Mage::logException($e); $result['error'] = $this->__('Unable to set Payment Method.'); } $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); } /** * Get Order by quoteId * * @throws Mage_Payment_Model_Info_Exception * @return Mage_Sales_Model_Order */ protected function _getOrder() { if (is_null($this->_order)) { $this->_order = Mage::getModel('sales/order')->load($this->getOnepage()->getQuote()->getId(), 'quote_id'); if (!$this->_order->getId()) { throw new Mage_Payment_Model_Info_Exception(Mage::helper('core')->__("Can not create invoice. Order was not found.")); } } return $this->_order; } /** * Create invoice * * @return Mage_Sales_Model_Order_Invoice */ protected function _initInvoice() { $items = array(); foreach ($this->_getOrder()->getAllItems() as $item) { $items[$item->getId()] = $item->getQtyOrdered(); } /* @var $invoice Mage_Sales_Model_Service_Order */ $invoice = Mage::getModel('sales/service_order', $this->_getOrder())->prepareInvoice($items); $invoice->setEmailSent(true)->register(); Mage::register('current_invoice', $invoice); return $invoice; } /** * Create order action */ public function saveOrderAction() { if (!$this->_validateFormKey()) { $this->_redirect('*/*'); return; } if ($this->_expireAjax()) { return; } $result = array(); try { $requiredAgreements = Mage::helper('checkout')->getRequiredAgreementIds(); if ($requiredAgreements) { $postedAgreements = array_keys($this->getRequest()->getPost('agreement', array())); $diff = array_diff($requiredAgreements, $postedAgreements); if ($diff) { $result['success'] = false; $result['error'] = true; $result['error_messages'] = $this->__('Please agree to all the terms and conditions before placing the order.'); $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); return; } } $data = $this->getRequest()->getPost('payment', array()); if ($data) { $data['checks'] = Mage_Payment_Model_Method_Abstract::CHECK_USE_CHECKOUT | Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_COUNTRY | Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_CURRENCY | Mage_Payment_Model_Method_Abstract::CHECK_ORDER_TOTAL_MIN_MAX | Mage_Payment_Model_Method_Abstract::CHECK_ZERO_TOTAL; $this->getOnepage()->getQuote()->getPayment()->importData($data); } $this->getOnepage()->saveOrder(); $redirectUrl = $this->getOnepage()->getCheckout()->getRedirectUrl(); $result['success'] = true; $result['error'] = false; } catch (Mage_Payment_Model_Info_Exception $e) { $message = $e->getMessage(); if (!empty($message)) { $result['error_messages'] = $message; } $result['goto_section'] = 'payment'; $result['update_section'] = array( 'name' => 'payment-method', 'html' => $this->_getPaymentMethodsHtml() ); } catch (Mage_Core_Exception $e) { Mage::logException($e); Mage::helper('checkout')->sendPaymentFailedEmail($this->getOnepage()->getQuote(), $e->getMessage()); $result['success'] = false; $result['error'] = true; $result['error_messages'] = $e->getMessage(); $gotoSection = $this->getOnepage()->getCheckout()->getGotoSection(); if ($gotoSection) { $result['goto_section'] = $gotoSection; $this->getOnepage()->getCheckout()->setGotoSection(null); } $updateSection = $this->getOnepage()->getCheckout()->getUpdateSection(); if ($updateSection) { if (isset($this->_sectionUpdateFunctions[$updateSection])) { $updateSectionFunction = $this->_sectionUpdateFunctions[$updateSection]; $result['update_section'] = array( 'name' => $updateSection, 'html' => $this->$updateSectionFunction() ); } $this->getOnepage()->getCheckout()->setUpdateSection(null); } } catch (Exception $e) { Mage::logException($e); Mage::helper('checkout')->sendPaymentFailedEmail($this->getOnepage()->getQuote(), $e->getMessage()); $result['success'] = false; $result['error'] = true; $result['error_messages'] = $this->__('There was an error processing your order. Please contact us or try again later.'); } $this->getOnepage()->getQuote()->save(); /** * when there is redirect to third party, we don't want to save order yet. * we will save the order in return action. */ if (isset($redirectUrl)) { $result['redirect'] = $redirectUrl; } $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); } /** * Filtering posted data. Converting localized data if needed * * @param array * @return array */ protected function _filterPostData($data) { $data = $this->_filterDates($data, array('dob')); return $data; } /** * Check can page show for unregistered users * * @return boolean */ protected function _canShowForUnregisteredUsers() { return Mage::getSingleton('customer/session')->isLoggedIn() || $this->getRequest()->getActionName() == 'index' || Mage::helper('checkout')->isAllowedGuestCheckout($this->getOnepage()->getQuote()) || !Mage::helper('checkout')->isCustomerMustBeLogged(); } }

Step 4. Now create new backend controller. Suppose we want to override backend controller Mage_Adminhtml_Customer_OnlineController then we will create one controller class in our module in directory app/code/local/ExtendTree/OverrideControllers/adminhtml/customer/ by name OnlineController.php

require_once(Mage::getModuleDir('controllers', 'Mage_Adminhtml') . DS . 'Customer/OnlineController.php'); class ExtendTree_OverrideControllers_Adminhtml_Customer_OnlineController extends Mage_Adminhtml_Customer_OnlineController { public function indexAction() { $this->_title($this->__('Customers'))->_title($this->__('Online Customers')); if ($this->getRequest()->getParam('ajax')) { $this->_forward('grid'); return; } $this->loadLayout(); $this->_setActiveMenu('customer/online'); $this->_addContent($this->getLayout()->createBlock('adminhtml/customer_online', 'customers')); $this->_addBreadcrumb(Mage::helper('customer')->__('Customers'), Mage::helper('customer')->__('Customers')); $this->_addBreadcrumb(Mage::helper('customer')->__('Online Customers'), Mage::helper('customer')->__('Online Customers')); $this->renderLayout(); } protected function _isAllowed() { return Mage::getSingleton('admin/session')->isAllowed('customer/online'); } }

That's it..!! Same way we can override any core frontend or admin controler

Thank you..!!

"The easy way for everything."

Magento 1.x ® Rewrite- magento rewrite Helpers, Blocks, Models


How to rewrite Magneto core classes??

  • Step 1. Create global configuration File
  • Step 2. Create module configuration file
  • Step 3. Create new helper class
  • Step 4. Create new Model class
  • Step 5. Create new Block class

Step 1. Each Module should have one Namespace & Module name. Name space could be some company name etc. & module name should be something that represents module functionality. So let suppose Namespace is ExtendTree and Module name is RewriteClasses Now Create Global Configuration File inside root directory /app/etc/modules as name "ExtendTree_RewriteClasses.xml"

<!--xml version="1.0" encoding="UTF-8"?--> <config> <modules> <ExtendTree_RewriteClasses> <active>true</active> <codePool>local</codePool> </ExtendTree_RewriteClasses> </modules> </config>

Step 2. Now Create Module Configuration File inside the directory /app/code/local/ExtendTree/RewriteClasses /etc as name "config.xml"

<!--xml version="1.0"?--> <config> <modules> <ExtendTree_RewriteClasses> <version>0.0.1</version> </ExtendTree_RewriteClasses> </modules> <global> <blocks> <!--Admin Sales Order Grid Block--> <adminhtml> <rewrite> <sales_order_grid>ExtendTree_RewriteClasses_Block_Sales_Order_Grid</sales_order_grid> </rewrite> </adminhtml> <!--Admin Sales Order Grid Block--> </blocks> <models> <!--Customer Address Region Collection Model--> <adminhtml> <rewrite> <customer_renderer_region>ExtendTree_RewriteClasses_Model_Customer_Renderer_Region</customer_renderer_region> </rewrite> </adminhtml> <!--Customer Address Region Collection Model--> </models> <!--Product Attributes Helper--> <helpers> <adminhtml> <catalog_product_edit_action_attribute> <data>ExtendTree_RewriteClasses_Catalog_Product_Edit_Action_Attribute</data> </catalog_product_edit_action_attribute> </adminhtml> </helpers> <!--Product Attributes Helper--> </global> </config>

Step 3. Now create the helper class. Suppose we want to rewrite class Mage_Adminhtml_Helper_Catalog_Product_Edit_Action_Attribute then we will create one helper class in our module in directory app/code/local/ExtendTree/RewriteClasses/Helper/Catalog/Product/Edit/Action/ by name Attribute.php

class ExtendTree_RewriteClasses_Helper_Catalog_Product_Edit_Action_Attribute extends Mage_Adminhtml_Helper_Catalog_Product_Edit_Action_Attribute { /** * Selected products for mass-update * * @var Mage_Catalog_Model_Entity_Product_Collection */ protected $_products; /** * Array of same attributes for selected products * * @var Mage_Eav_Model_Mysql4_Entity_Attribute_Collection */ protected $_attributes; /** * Excluded from batch update attribute codes * * @var array */ protected $_excludedAttributes = array('url_key'); /** * Return product collection with selected product filter * Product collection didn't load * * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */ public function getProducts() { if (is_null($this->_products)) { $productsIds = $this->getProductIds(); if (!is_array($productsIds)) { $productsIds = array(0); } $this->_products = Mage::getResourceModel('catalog/product_collection') ->setStoreId($this->getSelectedStoreId()) ->addIdFilter($productsIds); } return $this->_products; } /** * Return array of selected product ids from post or session * * @return array|null */ public function getProductIds() { $session = Mage::getSingleton('adminhtml/session'); if ($this->_getRequest()->isPost() && $this->_getRequest()->getActionName() == 'edit') { $session->setProductIds($this->_getRequest()->getParam('product', null)); } return $session->getProductIds(); } /** * Return selected store id from request * * @return integer */ public function getSelectedStoreId() { return (int) $this->_getRequest()->getParam('store', Mage_Core_Model_App::ADMIN_STORE_ID); } /** * Return array of attribute sets by selected products * * @return array */ public function getProductsSetIds() { return $this->getProducts()->getSetIds(); } /** * Return collection of same attributes for selected products without unique * * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection */ public function getAttributes() { if (is_null($this->_attributes)) { $this->_attributes = Mage::getSingleton('eav/config') ->getEntityType(Mage_Catalog_Model_Product::ENTITY) ->getAttributeCollection() ->addIsNotUniqueFilter() ->setInAllAttributeSetsFilter($this->getProductsSetIds()); if ($this->_excludedAttributes) { $this->_attributes->addFieldToFilter('attribute_code', array('nin' => $this->_excludedAttributes)); } // check product type apply to limitation and remove attributes that impossible to change in mass-update $productTypeIds = $this->getProducts()->getProductTypeIds(); foreach ($this->_attributes as $attribute) { /* @var $attribute Mage_Catalog_Model_Entity_Attribute */ foreach ($productTypeIds as $productTypeId) { $applyTo = $attribute->getApplyTo(); if (count($applyTo) > 0 && !in_array($productTypeId, $applyTo)) { $this->_attributes->removeItemByKey($attribute->getId()); break; } } } } return $this->_attributes; } /** * Return product ids that not available for selected store * * @deprecated since 1.4.1 * @return array */ public function getProductsNotInStoreIds() { return array(); } }

Step 4. Now create the model class. Suppose we want to rewrite class Mage_Adminhtml_Model_Customer_Renderer_Region then we will create one model class in our module in directory app/code/local/ExtendTree/RewriteClasses/Model/Customer/Renderer by name Region.php

class ExtendTree_RewriteClasses_Model_Customer_Renderer_Region extends Mage_Adminhtml_Model_Customer_Renderer_Region { /** * Country region collections * * array( * [$countryId] => Varien_Data_Collection_Db * ) * * @var array */ static protected $_regionCollections; public function render(Varien_Data_Form_Element_Abstract $element) { $html = '<tr>' . "\n"; $countryId = false; if ($country = $element->getForm()->getElement('country_id')) { $countryId = $country->getValue(); } $regionCollection = false; if ($countryId) { if (!isset(self::$_regionCollections[$countryId])) { self::$_regionCollections[$countryId] = Mage::getModel('directory/country') ->setId($countryId) ->getLoadedRegionCollection() ->toOptionArray(); } $regionCollection = self::$_regionCollections[$countryId]; } $regionId = intval($element->getForm()->getElement('region_id')->getValue()); $htmlAttributes = $element->getHtmlAttributes(); foreach ($htmlAttributes as $key => $attribute) { if ('type' === $attribute) { unset($htmlAttributes[$key]); break; } } // Output two elements - for 'region' and for 'region_id'. // Two elements are needed later upon form post - to properly set data to address model, // otherwise old value can be left in region_id attribute and saved to DB. // Depending on country selected either 'region' (input text) or 'region_id' (selectbox) is visible to user $regionHtmlName = $element->getName(); $regionIdHtmlName = str_replace('region', 'region_id', $regionHtmlName); $regionHtmlId = $element->getHtmlId(); $regionIdHtmlId = str_replace('region', 'region_id', $regionHtmlId); if ($regionCollection && count($regionCollection) > 0) { $elementClass = $element->getClass(); $html.= '<td class="label">' . $element->getLabelHtml() . '</td>'; $html.= '<td class="value">'; $html .= '<select id="' . $regionIdHtmlId . '" name="' . $regionIdHtmlName . '" ' . $element->serialize($htmlAttributes) . '>' . "\n"; foreach ($regionCollection as $region) { $selected = ($regionId == $region['value']) ? ' selected="selected"' : ''; $value = is_numeric($region['value']) ? (int) $region['value'] : ""; $html.= '<option value="' . $value . '"' . $selected . '>' . Mage::helper('adminhtml')->escapeHtml(Mage::helper('directory')->__($region['label'])) . '</option>'; } $html.= '</select>' . "\n"; $html .= '<input type="hidden" name="' . $regionHtmlName . '" id="' . $regionHtmlId . '" value=""/>'; $html.= '</td>'; $element->setClass($elementClass); } else { $element->setClass('input-text'); $html.= '<td class="label"><label for="' . $element->getHtmlId() . '">' . $element->getLabel() . ' <span class="required" style="display:none">*</span></label></td>'; $element->setRequired(false); $html.= '<td class="value">'; $html .= '<input id="' . $regionHtmlId . '" name="' . $regionHtmlName . '" value="' . $element->getEscapedValue() . '" ' . $element->serialize($htmlAttributes) . "/>" . "\n"; $html .= '<input type="hidden" name="' . $regionIdHtmlName . '" id="' . $regionIdHtmlId . '" value=""/>'; $html .= '</td>' . "\n"; } $html.= '</tr>' . "\n"; return $html; } }

Step 5. Now create the Block class. Suppose we want to rewrite class Mage_Adminhtml_Block_Sales_Order_Grid then we will create one block class in our module in directory app/code/local/ExtendTree/RewriteClasses/Block/Sales/Order by name Grid.php

class ExtendTree_RewriteClasses_Block_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid { public function __construct() { parent::__construct(); $this->setId('sales_order_grid'); $this->setUseAjax(true); $this->setDefaultSort('created_at'); $this->setDefaultDir('DESC'); $this->setSaveParametersInSession(true); } /** * Retrieve collection class * * @return string */ protected function _getCollectionClass() { return 'sales/order_grid_collection'; } protected function _prepareCollection() { $collection = Mage::getResourceModel($this->_getCollectionClass()); $this->setCollection($collection); return parent::_prepareCollection(); } protected function _prepareColumns() { $this->addColumn('real_order_id', array( 'header' => Mage::helper('sales')->__('Order #'), 'width' => '80px', 'type' => 'text', 'index' => 'increment_id', )); if (!Mage::app()->isSingleStoreMode()) { $this->addColumn('store_id', array( 'header' => Mage::helper('sales')->__('Purchased From (Store)'), 'index' => 'store_id', 'type' => 'store', 'store_view' => true, 'display_deleted' => true, )); } $this->addColumn('created_at', array( 'header' => Mage::helper('sales')->__('Purchased On'), 'index' => 'created_at', 'type' => 'datetime', 'width' => '100px', )); $this->addColumn('billing_name', array( 'header' => Mage::helper('sales')->__('Bill to Name'), 'index' => 'billing_name', )); $this->addColumn('shipping_name', array( 'header' => Mage::helper('sales')->__('Ship to Name'), 'index' => 'shipping_name', )); $this->addColumn('base_grand_total', array( 'header' => Mage::helper('sales')->__('G.T. (Base)'), 'index' => 'base_grand_total', 'type' => 'currency', 'currency' => 'base_currency_code', )); $this->addColumn('grand_total', array( 'header' => Mage::helper('sales')->__('G.T. (Purchased)'), 'index' => 'grand_total', 'type' => 'currency', 'currency' => 'order_currency_code', )); $this->addColumn('status', array( 'header' => Mage::helper('sales')->__('Status'), 'index' => 'status', 'type' => 'options', 'width' => '70px', 'options' => Mage::getSingleton('sales/order_config')->getStatuses(), )); if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) { $this->addColumn('action', array( 'header' => Mage::helper('sales')->__('Action'), 'width' => '50px', 'type' => 'action', 'getter' => 'getId', 'actions' => array( array( 'caption' => Mage::helper('sales')->__('View'), 'url' => array('base' => '*/sales_order/view'), 'field' => 'order_id', 'data-column' => 'action', ) ), 'filter' => false, 'sortable' => false, 'index' => 'stores', 'is_system' => true, )); } $this->addRssList('rss/order/new', Mage::helper('sales')->__('New Order RSS')); $this->addExportType('*/*/exportCsv', Mage::helper('sales')->__('CSV')); $this->addExportType('*/*/exportExcel', Mage::helper('sales')->__('Excel XML')); return parent::_prepareColumns(); } protected function _prepareMassaction() { $this->setMassactionIdField('entity_id'); $this->getMassactionBlock()->setFormFieldName('order_ids'); $this->getMassactionBlock()->setUseSelectAll(false); if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/cancel')) { $this->getMassactionBlock()->addItem('cancel_order', array( 'label' => Mage::helper('sales')->__('Cancel'), 'url' => $this->getUrl('*/sales_order/massCancel'), )); } if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/hold')) { $this->getMassactionBlock()->addItem('hold_order', array( 'label' => Mage::helper('sales')->__('Hold'), 'url' => $this->getUrl('*/sales_order/massHold'), )); } if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/unhold')) { $this->getMassactionBlock()->addItem('unhold_order', array( 'label' => Mage::helper('sales')->__('Unhold'), 'url' => $this->getUrl('*/sales_order/massUnhold'), )); } $this->getMassactionBlock()->addItem('pdfinvoices_order', array( 'label' => Mage::helper('sales')->__('Print Invoices'), 'url' => $this->getUrl('*/sales_order/pdfinvoices'), )); $this->getMassactionBlock()->addItem('pdfshipments_order', array( 'label' => Mage::helper('sales')->__('Print Packingslips'), 'url' => $this->getUrl('*/sales_order/pdfshipments'), )); $this->getMassactionBlock()->addItem('pdfcreditmemos_order', array( 'label' => Mage::helper('sales')->__('Print Credit Memos'), 'url' => $this->getUrl('*/sales_order/pdfcreditmemos'), )); $this->getMassactionBlock()->addItem('pdfdocs_order', array( 'label' => Mage::helper('sales')->__('Print All'), 'url' => $this->getUrl('*/sales_order/pdfdocs'), )); $this->getMassactionBlock()->addItem('print_shipping_label', array( 'label' => Mage::helper('sales')->__('Print Shipping Labels'), 'url' => $this->getUrl('*/sales_order_shipment/massPrintShippingLabel'), )); return $this; } public function getRowUrl($row) { if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) { return $this->getUrl('*/sales_order/view', array('order_id' => $row->getId())); } return false; } public function getGridUrl() { return $this->getUrl('*/*/grid', array('_current' => true)); } }

That's it..!! This way we can rewrite any core class in our custom module

Thank you..!!

"The easy way for everything."

Magento 1.x ® Cron Job- How to create basic cron module.


How to use Magneto crons??

  • Step 1. Create global configuration File
  • Step 2. Create module configuration file
  • Step 3. Create module model observer

Step 1. Each Module should have one Namespace & Module name. Name space could be some company name etc. & module name should be something that represents module functionality. So let suppose Namespace is ExtendTree and Module name is SimpleCrons. Now Create Global Configuration File inside root directory /app/etc/modules as name "ExtendTree_SimpleCrons.xml"

<!--xml version="1.0" encoding="UTF-8"?--> <config> <modules> <ExtendTree_SimpleCrons> <active>true</active> <codePool>local</codePool> </ExtendTree_SimpleCrons> </modules> </config>

Step 2. Now Create Module Configuration File inside the directory /app/code/local/ExtendTree/SimpleCrons/etc as name "config.xml"

<!--xml version="1.0"?--> <config> <modules> <ExtendTree_SimpleCrons> <version>0.0.1</version> </ExtendTree_SimpleCrons> </modules> <global> <models> <simplecrons> <class>ExtendTree_SimpleCrons_Model</class> </simplecrons> </models> </global> <crontab> <jobs> <first_cron_setup_in_one_minute> <schedule> <cron_expr>* * * * *</cron_expr> </schedule> <run> <model>simplecrons/cron::doThisInMinute</model> </run> </first_cron_setup_in_one_minute> </jobs> <jobs> <second_cron_setup_in_two_minute> <schedule> <cron_expr>*/2 * * * *</cron_expr> </schedule> <run> <model>simplecrons/cron::doThisInTwoMinute</model> </run> </second_cron_setup_in_two_minute> </jobs> </crontab> </config>

Step 3. Now next thing is to create model cron inside the directory /app/code/local/ExtendTree/SimpleCrons/Model/ as name "Cron.php"

class ExtendTree_SimpleCrons_Model_Cron { /* * This cron will run in one minute. */ public function doThisInMinute() { /** * Write your custom code here */ Mage::log('One minute completed', null, 'FirstCron.log'); } /* * This cron will run in two minutea. */ public function doThisInTwoMinute() { /** * Write your custom code here. */ Mage::log('Two minute completed', null, 'SecondCron.log'); } }

That's it..!! Now as per your server cron setup. It should create a log file in one and two minute interval inside the directory /var/log

Thank you..!!

"The easy way for everything."

Magento 1.x® Event Observers- Create basic events


How to use Magneto events observers??

  • Step 1. Create global configuration File
  • Step 2. Create module configuration file
  • Step 3. Create module model observer

Step 1. Each Module should have one Namespace & Module name. Name space could be some company name etc. & module name should be something that represents module functionality. So let suppose Namespace is ExtendTree and Module name is SimpleObservers. Now Create Global Configuration File inside root directory /app/etc/modules as name "ExtendTree_SimpleObservers.xml"

<!--xml version="1.0" encoding="UTF-8"?--> <config> <modules> <ExtendTree_SimpleObservers> <active>true</active> <codePool>local</codePool> </ExtendTree_SimpleObservers> </modules> </config>

Step 2. Now Create Module Configuration File inside the directory /app/code/local/ExtendTree/SimpleObservers/etc as name "config.xml"

<!--xml version="1.0"?--> <config> <modules> <ExtendTree_SimpleObservers> <version>0.0.1</version> </ExtendTree_SimpleObservers> </modules> <global> <events> <!--Event on each page load in frontend Start--> <controller_front_init_before> <observers> <extendtree_first_observer> <type>singleton</type> <class>ExtendTree_SimpleObservers_Model_Observer</class> <method>controller_front_init_before</method> </extendtree_first_observer> </observers> </controller_front_init_before> <!--Event on each page load in frontend Start--> <!--Event on customer registeration Start--> <customer_register_success> <observers> <extendtree_second_observer> <type>singleton</type> <class>ExtendTree_SimpleObservers_Model_Observer</class> <method>customer_register_success</method> </extendtree_second_observer> </observers> </customer_register_success> <!--Event on customer registeration End--> <!--Event on order place Start--> <sales_quote_add_item> <observers> <extendtree_third_observer> <type>singleton</type> <class>ExtendTree_SimpleObservers_Model_Observer</class> <method>sales_quote_add_item</method> </extendtree_third_observer> </observers> </sales_quote_add_item> <!--Event on order place End--> <!--Event on order place Start--> <sales_order_place_after> <observers> <extendtree_fourth_observer> <type>singleton</type> <class>ExtendTree_SimpleObservers_Model_Observer</class> <method>sales_order_place_after</method> </extendtree_fourth_observer> </observers> </sales_order_place_after> <!--Event on order place End--> </events> </global> </config>

Step 3. Now next thing is to create model observer inside the directory /app/code/local/ExtendTree/SimpleObservers/Model/ as name "Observer.php"

class ExtendTree_SimpleObservers_Model_Observer { /* * This observer will be called on each page load in frontend. */ public function controller_front_init_before($observer) { Mage::log('Frontend Page loaded', null, 'FirstObserver.log'); } /* * This observer will be called on each Customer registeration. */ public function customer_register_success($observer) { Mage::log('Customer registered', null, 'SecondObserver.log'); } /* * This observer will be called when visitor add product into cart. */ public function sales_quote_add_item($observer) { Mage::log('One Product Added into Cart', null, 'ThirdObserver.log'); } /* * This observer will be called when an order will be placed. */ public function sales_order_place_after($observer) { Mage::log('One order has been placed', null, 'FourthObserver.log'); } }

That's it..!! Now try to place an order, customer registeration, add product to cart, load frontend. It should create a log file inside the directory /var/log

 

Thank you..!!

"The easy way for everything."

Magento 1.x ® basic frontend module


How to create Magneto frontend (Hello World) module??

  • Step 1. Create Global Configuration File
  • Step 2. Create Module Configuration file
  • Step 3. Create Module Frontend controller
  • Step 4. Create Module Frontend Layout file
  • Step 5. Create Module Frontend Template file

 

Step 1. Each Module should have one Namespace & Module name. Name space could be some company name etc. & module name should be something that represents module functionality. So let suppose Namespace is ExtendTree and Module name is FrontendModule. Now Create Global Configuration File inside root directory /app/etc/modules as name "ExtendTree_FrontendModule.xml"

<!--xml version="1.0" encoding="UTF-8"?--> <config> <modules> <ExtendTree_FrontendModule> <active>true</active> <codePool>local</codePool> </ExtendTree_FrontendModule> </modules> </config>

 

Step 2. Now Create Module Configuration File inside the directory /app/code/local/ExtendTree/FrontendModule/etc as name "config.xml"

<!--xml version="1.0"?--> <config> <modules> <ExtendTree_FrontendModule> <version>0.0.1</version> </ExtendTree_FrontendModule> </modules> <frontend> <routers> <frontendmodule> <use>standard</use> <args> <module>ExtendTree_FrontendModule</module> <frontName>helloworld</frontName> </args> </frontendmodule> </routers> <layout> <updates> <frontendmodule> <file>extendtree/frontendmodule.xml</file> </frontendmodule> </updates> </layout> </frontend> </config>

 

Step 3. Now next thing is to create frontend controller inside the directory /app/code/local/ExtendTree/FrontendModule/controllers as name "IndexController.php"

class ExtendTree_Frontendmodule_IndexController extends Mage_Core_Controller_Front_Action { public function indexAction() { $this->loadLayout(); $this->renderLayout(); } }

 

Step 4. Now create frontend layout file inside the directory /app/design/frontend/base/default/layout/extendtree as name "frontendmodule.xml"

<!--xml version="1.0"?--> <layout version="1.0.0"> <frontendmodule_index_index> <reference name="root"> <action method="setTemplate"> <template>page/1column.phtml</template> </action> </reference> <reference name="content"> <block type="core/template" name="frontendmodule" template="extendtree/frontendmodule.phtml" /> </reference> </frontendmodule_index_index> </layout>

 

Step 5. Last step is to create frontend template file inside the directory /app/design/frontend/base/default/template/extendtree as name "frontendmodule.phtml"

<h1><!--php echo $this--->__('Hello World..!!')?></h1> <h2><!--php echo $this--->__('I just Created my first magento frontend module.')?></h2>

 

That's it..!! Now just run your module by URL as "YOUR_SITE_BASE_URL"/helloworld

 

 

Thank you..!!

"The easy way for everything."

Magento® 1.x Installation -Video Tutorial


Complete Instructions

 

Thank you..!!

"The easy way for everything."

Magento® 2.x How to create custom theme


How to create custom theme in Magneto 2 ??

Step 1. Create Theme Directory. Ex. magento2/app/design/frontend/extendtree/customtheme.

Step 2. Now create a theme.xml file. Directory will be like app/design/frontend/extendtree/customtheme/theme.xml

<theme xmlns:xsi=&#8221;http://www.w3.org/2001/XMLSchema-instance&#8221; xsi:noNamespaceSchemaLocation=&#8221;../../../../lib/internal/ Magento/Framework/Config/etc/theme.xsd&#8221;> <title>Extendtree custom theme</title> <parent>Magento/blank</parent> <media> <preview_image>media/customtheme.jpg</preview_image> </media> </theme>

Note: upload theme image inside directory: app/design/frontend/extendtree/customtheme/media/customtheme.jpg

Step 3. Add a composer.json file to the theme directory : magento2/app/design/frontend/extendtree/customtheme/composer.json

{ "name": "extendtree/customtheme", "description": "N/A", "require": { "php": "~5.5.0|~5.6.0|~7.0.0", "magento/theme-frontend-blank": "100.0.*", "magento/framework": "100.0.*" }, "type": "customtheme", "version": "100.0.1", "license": [ "OSL-3.0", "AFL-3.0" ], "autoload": { "files": [ "registration.php" ] } }

Step 4. Add registration.php file in theme directory: magento2/app/design/frontend/extendtree/customtheme/registration.php

<!--php /** * Copyright &#169; 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::THEME, 'frontend/extendtree/customtheme', __DIR__ ); </xmp--></strong></div></p> <p><strong>Step 5. </strong>Add file default.xml in directory <strong>magento2/app/design/frontend/extendtree/customtheme/Magento_Theme/layout/default.xml </strong></p> <p><div class="source-code" style="font-weight: 5px; background-color: #a5c878"><strong><xmp> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="logo"> <arguments> <argument name="logo_file" xsi:type="string">/web/images/customtheme_logo.png</argument> <argument name="logo_img_width" xsi:type="number">300</argument> <argument name="logo_img_height" xsi:type="number">300</argument> </arguments> </referenceBlock> </body> </page>

Note: custom theme logo need to upload in directory: /app/design/frontend/extendtree/customtheme/web/images/customtheme_logo

Step 6. That's it. Now your theme is fully configured with magento system. To confirm this check in backend :Admin-> Content > Design > Themes

Step 7. Now select your theme inside Admin-> Stores > Configuration > Design & clear the caches.

 

That's it..!!

Thank you..!!

"The easy way for everything."

Magento® 2.x How to create basic frontend module

How to create basic frontend module in Magneto 2 ??

Step 1. Decide a name space(Extendtree) & module name(Helloworld). Ex. Extendtree_Helloworld

Step 2. create directory as: magento2/app/code/Extendtree/Helloworld

Step 3. Add a xml file named "module.xml" in directory: magento2/app/code/Extendtree/Helloworld/etc/module.xml

<!--xml version="1.0"?--> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="Extendtree_Helloworld" setup_version="0.0.1"/> </config>

Step 4. Create a registration.php in directory: magento2/app/code/Extendtree/Helloworld/registration.php

<!--php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Extendtree_Helloworld', __DIR__ ); </xmp--></strong> </div></p> <p><strong>Step 5. </strong>Now we have to enable our module, we have two ways to do this.<br> Enable module from config.php (located in directory <strong>magento2/app/etc/config.php </strong>) </p> <p><div class="source-code" style="font-weight: 5px; background-color: #a5c878"><strong><xmp> .............. 'Extendtree_Helloworld' => 1, .............

Or First run the command php bin/magento module:status to checked out enable modules in our magento2
To enable module use the command php bin/magento module:enable Extendtree_Helloworld

Step 6. Just after step 5 you have to execute a command bin/magento setup:upgrade
Else our magento site will through an error as Please upgrade your database: Run “bin/magento setup:upgrade” from the Magento root directory.

Step 7. Now our module is fully configured with magento system. To confirm this check in backend :Store->Configuration->Advanced

Step 8. Now create routers for your module. First add routes.xml in directory magento2/app/code/Extendtree/Helloworld/etc/frontend/routes.xml

<!--xml version="1.0"?--> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd"> <router id="standard"> <route id="extendtree" frontName="helloworld"> <module name="Extendtree_Helloworld" /> </route> </router> </config>

Step 9. Add controller to handle the requests in directory magento2/app/code/Extendtree/Helloworld/Controller/Test/Helloworld.php

<!--php namespace Extendtree\Helloworld\Controller\Test; class Helloworld extends \Magento\Framework\App\Action\Action { public function __construct( \Magento\Framework\App\Action\Context $context) { return parent::__construct($context); } public function execute() { echo 'Hello World'; exit; } } </xmp--></strong> </div></p> <p><strong>Step 10. </strong>Now open URL : <strong>http://__BASEURL__/extendtree/test/helloworld</strong></p> <p>Here is how the URL composed: <strong>http://__BASEURL__/route_id/controller_name/front_name</strong> </p> <p>&nbsp;</p> <p>Thank you..!!</p> <p><strong style="color: #de036f;">"The easy way for everything."</strong></p> </div> </div> <div style='clear: both;'></div> </div> <div class='post-footer'> <div class='post-footer-line post-footer-line-1'> <span class='post-author vcard'> Posted by <span class='fn' itemprop='author' itemscope='itemscope' itemtype='http://schema.org/Person'> <meta content='https://www.blogger.com/profile/04822371922444829481' itemprop='url'/> <a class='g-profile' href='https://www.blogger.com/profile/04822371922444829481' rel='author' title='author profile'> <span itemprop='name'> Unknown </span> </a> </span> </span> <span class='post-timestamp'> at <meta content='http://thisisakhilgupta.blogspot.com/2016/09/magento-2x-how-to-create-basic-frontend.html' itemprop='url'/> <a class='timestamp-link' href='https://thisisakhilgupta.blogspot.com/2016/09/magento-2x-how-to-create-basic-frontend.html' rel='bookmark' title='permanent link'> <abbr class='published' itemprop='datePublished' title='2016-09-03T07:58:00-07:00'> 07:58:00 </abbr> </a> </span> <span class='reaction-buttons'> </span> <span class='post-comment-link'> <a class='comment-link' href='https://thisisakhilgupta.blogspot.com/2016/09/magento-2x-how-to-create-basic-frontend.html#comment-form' onclick=''> No comments : </a> </span> <span class='post-backlinks post-comment-link'> </span> <span class='post-icons'> </span> <div class='post-share-buttons goog-inline-block'> <a class='goog-inline-block share-button sb-email' href='https://www.blogger.com/share-post.g?blogID=5409553795945628732&postID=672313850244854459&target=email' target='_blank' title='Email This'> <span class='share-button-link-text'> Email This </span> </a> <a class='goog-inline-block share-button sb-blog' href='https://www.blogger.com/share-post.g?blogID=5409553795945628732&postID=672313850244854459&target=blog' onclick='window.open(this.href, "_blank", "height=270,width=475"); return false;' target='_blank' title='BlogThis!'> <span class='share-button-link-text'> BlogThis! </span> </a> <a class='goog-inline-block share-button sb-twitter' href='https://www.blogger.com/share-post.g?blogID=5409553795945628732&postID=672313850244854459&target=twitter' target='_blank' title='Share to X'> <span class='share-button-link-text'> Share to X </span> </a> <a class='goog-inline-block share-button sb-facebook' href='https://www.blogger.com/share-post.g?blogID=5409553795945628732&postID=672313850244854459&target=facebook' onclick='window.open(this.href, "_blank", "height=430,width=640"); return false;' target='_blank' title='Share to Facebook'> <span class='share-button-link-text'> Share to Facebook </span> </a> <a class='goog-inline-block share-button sb-pinterest' href='https://www.blogger.com/share-post.g?blogID=5409553795945628732&postID=672313850244854459&target=pinterest' target='_blank' title='Share to Pinterest'> <span class='share-button-link-text'> Share to Pinterest </span> </a> </div> </div> <div class='post-footer-line post-footer-line-2'> <span class='post-labels'> Labels: <a href='https://thisisakhilgupta.blogspot.com/search/label/Magento%202.x' rel='tag'> Magento 2.x </a> , <a href='https://thisisakhilgupta.blogspot.com/search/label/Magento-%20An%20Ecommerce%20Framework' rel='tag'> Magento- An Ecommerce Framework </a> </span> </div> <div class='post-footer-line post-footer-line-3'> <span class='post-location'> </span> </div> </div> </div> </div> <div class='post-outer'> <div class='post hentry uncustomized-post-template' itemprop='blogPost' itemscope='itemscope' itemtype='http://schema.org/BlogPosting'> <meta content='5409553795945628732' itemprop='blogId'/> <meta content='5014525985433203479' itemprop='postId'/> <a name='5014525985433203479'></a> <h3 class='post-title entry-title' itemprop='name'> <a href='https://thisisakhilgupta.blogspot.com/2016/09/magento-2x-create-custom-event.html'> Magento&#174; 2.x Create Custom Event </a> </h3> <div class='post-header'> <div class='post-header-line-1'></div> </div> <div class='post-body entry-content' id='post-body-5014525985433203479' itemprop='articleBody'> <div dir="ltr" style="text-align: left;" trbidi="on"> <br /> <div class="col3-set"> <div class="col-3"> <p style="color: #888; font: 1.2em/1.4em georgia, serif;"><h2>How to create custom events in Magneto 2 ??</h2></p> <p>&nbsp;</p> <p><strong>Step 1. </strong> app/code/Extendtree/Customevent/etc/events.xml</p> <p><div class="source-code" style="font-weight: 5px; background-color: #a5c878"><strong><xmp> <!--xml version="1.0"?--> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <event name="custom_event_name_here"> <observer name="custom_observer_name_here" instance="Extendtree/Customevent/Observer/Observer.php" /> </event> </config>

Step 2. Dispatch the event.

$this->_eventManager->dispatch('custom_event_name_here',['some_value => 1]);

Step 3. Create Observer file & declare method in app/code/Extendtree/Customevent/Observer/Observer.php

namespace Extendtree\Customevent\Observer; use Magento\Framework\Event\ObserverInterface; class Observer implements ObserverInterface{ public function __construct() {} public function execute(\Magento\Framework\Event\Observer $observer){ /**************Do Something****************/ /**************Do Something***************/ } }

 

Thank you..!!

"The easy way for everything."

Magento® 2.x Create simple module - Video Tutorial


Here is the complete steps to create magento 2.x custom module :
 

Complete Instructions

 

Thank you..!!

"The easy way for everything."

Magento® 2.x Configure Custom module - Video Tutorial


Here is the complete steps to configure magento 2.x custom module :
 

Complete Instructions

 

Thank you..!!

"The easy way for everything."

Magento® 2.x (An Ecommerce framework) Installation complete steps -Video Tutorial

Magento 2.x Community Edition Installation with sample data- Complete Steps- (The Easy way) System Preparation:
  • install Wamp Server (http://www.wampserver.com/en/)
  • Download Magento & it's sample data from (https://www.magentocommerce.com/download)

(I am using Magento Community Edition 2.0.2 with Sample Data.tar.bz2 (206 MB))


Thank you..!!
-  Akhil Gupta  

"The easy way for everything."