Posts

Showing posts from September, 2016

Magento 2 CSS and JavaScript not loading

If you are facing problem of css and js page load design after installation in magento2 please follow the following step-: open the terminal and navigate to magento web root  $ cd /var/www/html/magento2  Step 1.  $ php bin/magento setup:static-content:deploy  Step 2.  $ php bin/magento indexer:reindex Step 3. make sure apache “rewrite_module” is enable and then restart the server Step 4.  $ chown -R www-data:www-data /var/www/html/magento2  Step 5.  $ chmod -R 777 /var/www/html/magento2  Step 6. delete cache folder under var/cache The above step working. I hope this will work for you also. Command to change the mode (Developer,Production..etc) open the terminal and navigate to magento web root $ php bin/magento deploy:mode:show $ php bin/magento deploy:mode:set production

Event and Observers in Magento2

To create observer in magento2, first we need to define observer in file: app/code/Rahul/HelloWorld/etc/events.xml <?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="controller_action_catalog_product_save_entity_after">         <observer name="Rahul_HelloWorld_Product_Save_After" instance="Rahul\HelloWorld\Observer\ProductSaveAfter" />     </event> </config> Note: There are different places to create files for different handlers.     To create observer for frontend you can create file under : app/code/Rahul/HelloWorld/etc/frontend/event.xml     To create observer for frontend you can create file under : app/code/Rahul/HelloWorld/etc/adminhtml/event.xml     To create observer for both end, you need to cre...

Create log file in Magento2

$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log'); $logger = new \Zend\Log\Logger(); $logger->addWriter($writer); $logger->info('Your text message'); You can also print PHP objects and arrays like below : $logger->info(print_r($yourArray, true));

Create a simple module in Magento2

I have created a module with Namespace as Rahul and Module Name as HelloWorld Step1: Create a module.xml file in app/code/Rahul/HelloWorld/etc <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">     <module name="Rahul_HelloWorld" setup_version="1.0.0">     </module> </config> Step2: Create app/code/Rahul/HelloWorld/registration.php file <?php \Magento\Framework\Component\ComponentRegistrar::register(     \Magento\Framework\Component\ComponentRegistrar::MODULE,     'Rahul_HelloWorld',     __DIR__ ); Step3: Create a frontend router in app/code/Rahul/HelloWorld/etc/frontend/routes.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:...

Magento Registry: Mage::register

Magento registry is a great way of sharing information anywhere in your Magento store as they are static function.In other words Magento registry implies creation of new global variables which can be accessed anywhere within your Magento store. I have been wondering always,where is all the registry data stored in Magento ? I know that even singleton objects are stored in the registry. And registry is just a static array variable of the Mage class. Is registry different for different users ? I mean is it created on a per-user (per HTTP request) basis? For example,     Mage::register('foo', 'Hello World'); //set a value for foo     Mage::registry('foo'); //will this return hello world Is registry data stored in sessions ? If not how will Magento identify which user invoked the registry data ? <==============================================>       Magento Registry stored in the application’s memory,when ever your scri...

Magento orders states and statuses

Image
Each state can have one or several statuses and a status can have only one state. By default, statuses and states have often the same name, that is why it is a little confusing. Here is the list of statuses and states available by default. $order = Mage::getModel('sales/order')->loadByIncrementId('100000001'); $state = 'processing'; $status = 'Payment After Cancelled'; $comment = 'Changing state to Processing and status to Payment After Cancelled '; $isCustomerNotified = false; $order->setState($state, $status, $comment, $isCustomerNotified); $order->save(); $status can also take false value in order to only set order state, or true value for setting status by taking first status associated to this state. You can now adjust as you wish your order workflow in Magento.