Showing posts with label Magento 2. Show all posts
Showing posts with label Magento 2. Show all posts

How to Get Current DateTime of Store

The current date and time according to the timezone of store can be found using below code snippet.

In your class file inject instance of 'Timezone' as below.

protected $_timezone;
public function __construct(
    ....
    \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone,
    ....
) {
    ....
    $this->_timezone = $timezone;
    ....
}


Now, in your method, you can find the current date and time of store using below statement.
$this->_timezone->date()->format('Y-m-d H:i:s');
 

Incorrect dependency in class already exists in context object

Magento 2 classes have dependency injection in constructor method. One special object which is there is context.

The context object further provides many other objects. Apparently, if you have injected context object in your module's class which may further inheriting some Magento 2 class, you may not need to inject some objects which are already being provided by context object. This mechanism makes sure, your system does not end up with many duplicate objects occupying memory and leads to poor performance.

When your Magento 2 shop runs with developer mode, the system does not report any issue. But when you switch the mode to production, it reports the error.
Also, when you run php bin/magento setup:di:compile command, the system reports the error.

Now, to the point, how to solve the error which looks like something below, the class name may be different.
Errors during compilation:
Helper\Data
Incorrect dependency in class Helper\Data in vendor/xxx/Helper/Data.php
\Magento\Framework\SOME\CLASS already exists in context object

Total Errors Count: x.

As we have learned above, the object is already being provided by the context object. So, it does not need to be injected, instead retrieved from context object.
Step 1: Remove the object from your constructor which was reported as already exists.
Step 2: Assign your class property by retrieving the object from context object.
For example, if your constructor method looks like below and reported error for class ScopeConfigInterface.

    public function __construct(
        \Magento\Framework\App\Helper\Context $context,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
    ) {
        $this->_scopeConfig = $scopeConfig;
        
        parent::__construct($context);

    }

The rectification will look like below.

      public function __construct(
        \Magento\Framework\App\Helper\Context $context
    ) {
        $this->_scopeConfig = $context->getScopeConfig();
        
        parent::__construct($context);

    }

Hope, this will help you to rectify the error appeared while running php bin/magento setup:di:compile command.
Errors during compilation:
Incorrect dependency in class x.php
some class already exists in context object
Total Errors Count: x

Visit for affordable Magento 2 extensions which provides the most sought features only.

Sort By Ratings on Product Listing of Magento

Ever wondered what does your customers do to find the best and product from your catalog containing hundreds or thousands of products. 
Well, as a customer purchasing online rely more on the recommendations of other customers. 
Magento provides reviews and ratings module out of the box. Your customers can leave reviews and ratings for the products based on different criteria. These reviews can be useful to you for making the product as per the customer's expectations.
But, by publishing the reviews and ratings also helps the other customers  also to decide the purchase. When there are multiple similar kind of products in your catalog, the ratings will be even more important and useful for the customers.
Magento provides flexibility to sort the products by different attributes, however, sorting by ratings is missing.
Along with full use of review and ratings module, you should consider providing sorting by ratings and rich snippets of reviews.

If you are running your store on the Magento version 1, following product sorting extension for Magento 1 can be useful which is affordable from price point of view.
For the merchants who are running their store on Magento 2 platform, the product sorting extension is available here.

Sort By Discount for Magento Product Listing

So, you have just launched your cool webshop using the powerful Magento platform version 2.x. And now you want to attract customers by raining discounts to your new webstore running on Magento platform. 

Price of some products may be slashed using Magento's out of the box powerful features - Catalog price rules or special prices.

What if your customers see the heavily discounted products scattered on the listing/category page. 

What if your customers want to know which product in particular category or search result is offering the highest discount.

For making your customers feel cool, the sorting option to products by 'Heavily Discounted' is must. So, how can you offer this sorting option to your customers easily and quickly on the webshop running on the powerful Magento platform.

Well, there is an extension which offers this feature along with many other useful sorting options from customers' perspective.
If your store is running on Magento 2 platform, download the Product Sorting extension for Magento 2 and offer your customers the cool sorting options in no time to increase the conversion rate by putting the sought product ahead on category or search results pages.

Direct links to download the Sorting by New products, Popular products, Best seller products, top-rated products and most reviewed products for Magento software are below.

Easiest & Quick to Install Magento 2

Are you use to install Magento 2 software frequently in local environment to develop/test integrations and extensions? Are you tired of installing Magento 2 software frequently and interactions required in the web installer?

Magento 2 provides command line installation tool which takes all parameters at once and installs Magento 2 software without any further intervention of user. Sounds cool! So, below is the command to install Magento 2 software quickly and easily.

php bin\magento setup:install --base-url=http://127.0.0.1/magento2/ --db-host=YOUR_DB_HOST --db-name=YOUR_DB_NAME --db-user=YOUR_DB_USER --db-password=YOUR_DB_PASSWORD --admin-firstname=YOUR_ADMIN_FIRST_NAME --admin-lastname=YOUR_ADMIN_LAST_NAME --admin-email=YOUR_ADMIN_EMAIL --admin-user=YOUR_ADMIN_USERNAME --admin-password=YOUR_ADMIN_PASSWORD --language=en_US --currency=USD --timezone=America/Chicago --cleanup-database --sales-order-increment-prefix="ORD$" --session-save=files --use-rewrites=1 --use-sample-data

Replace the parameter values with your environment values and run the command in the directory where Magento 2 installation files reside.

Why Magento 2 extensions are priced too high



Magento 2 is a new technology stack which can withstand to the new technology trends in web development. The use of cutting edge stack enables the Magento 2 software even more flexible, adaptable and scalable.



Magento 2 was announced to be “stable” during late 2015. However, it was full of bugs and incurred development cost. Then, Magento 2 has started releasing in two channels – 2.0.x and 2.1.x and there are very less chances of a module which was developed for 2.0.x work in 2.1.x. So, the development companies had to put extra efforts in development and testing for each channel and since Magento introduces many changes from version to version the extensions need to be maintained at high cost.



The development companies constantly tries to improve their product. But they have to pass through a long process of approval if they are selling it on marketplace of Magento. If in between some customer purchases the extension, the possibility of support will be there if any needed corrections are identified after getting the extension live.


Putting all the above together, the development companies are spending a lot of efforts in developing and maintaining the extensions and as a consequence the cost of the extensions rise.

You may find Magento 2 extensions at cheap rates.

Sort by New Popular Ratings products Magento 2

How to add sorting options in Magento 2 on product listing and search results pages,

Here is a great extension to do it - https://marketplace.magento.com/mk-sortby.html

Adds sorting options worth customers' interest. Allows easy controls in backend to enable/disable/set default sorting options.

Sort by New Popular and Ratings of products

This extension works as a plugin in Magento 2 software. It adds following product sorting options on Magento 2 products listing pages - new products, popular (best selling) products, most reviewed products, top rates products. It will be easier for the customers to see the new items at top and with the other options like sort by best selling and ratings will boost confidence of shopping.
  • Implemented on Magento 2 plugins only
  • No control breaking configuration
  • 100% open source
  • Easy to enable/disable individual sorting option
  • Easy to manage different default sorting option for category pages
Buy sort by new and popular products extension for Magento 2.

Direct links to download the Sorting by New products, Popular products, Best seller products, top-rated products and most reviewed products for Magento software are below.

Unable to load theme magento2

If you are one of those who are facing issue "Unable to load theme" while registering a new Magento theme.

You might be experiencing below errors even after creating a new Magento2 theme and properly placing all the necessary files registration.php and theme.xml.
  • 'theme' table in database does not show your theme entry.
  • Content > Design > Theme in admin panel does not show your newly created theme entry.
  • setup:static-content:deploy command stuck while processing your theme.
Well, these all are very frustrating even though the registration.php and theme.xml files are correct.

Solution:
The issue could be file permission of the theme files. Strange!
  1.  Login as Magento file system owner.
  2. Navigate to Magento2 installation location.
  3. Run below commands.
    chown -R :nginx .   
    (replace 'nginx' by your web server user group name)

    find . -type d -exec chmod 770 {} \; && find . -type f -exec chmod 660 {} \; && chmod u+x bin/magento
More about Magento2 file system permission and ownership at http://devdocs.magento.com/guides/v2.0/install-gde/prereq/file-system-perms.html#install-perms-set. 

The theme registration issue should be resolved when you access your Magento2 store and run static-content:deploy command. "Unable to load theme" should be gone from console now.
  

Magento 2 save marketplace keys

Error: SSL certificate problem: unable to get local issuer certificate

 While saving the "Public Access Key" and "Private Access Key" in Magento 2 admin panel in Magento Marketplace settings, if you are getting the above error, the possibility is the ca-bundle.crt is not installed for the curl settings in your php.ini.

To resolve the error:
1) Open your php.ini file and locate following line [curl]
2) Enter below lines (make sure you enter correct path to the ca-bundle.crt file)
curl.cainfo="PATH_TO_FILE\ca-bundle.crt"
openssl.cafile="
PATH_TO_FILE\ca-bundle.crt"
The ca-bundle.crt file can be downloaded from https://github.com/bagder/ca-bundle/blob/e9175fec5d0c4d42de24ed6d84a06d504d5e5a09/ca-bundle.crt
3) Restart web server.

Hope the above solution helped you to resolve the error SSL certificate problem: unable to get local issuer certificate in Magento 2 admin panel while saving "Public Access Key" and "Private Access Key".

Magento 2: grunt refresh, grunt documentation commands are not working

jit-grunt: Plugin for the "xxxx" task not found.
If you have installed the plugin already, please setting the static mapping.
See https://github.com/shootaroo/jit-grunt#static-mappings

After installing Magento 2 and the node modules including grunt if you are facing error like above while executing the refresh and documentation tasks you may need to update your Gruntfile.js. (Below is the working solution in Magento 2 beta at the time of writing Oct 16, 2015)

For static mapping below code should be entered just below 'use strict'; statement. So, the top of your Gruntfile.js should look like.

..........

module.exports = function (grunt) {
    'use strict';

    require('jit-grunt')(grunt, {
        refresh: 'refresh',
        usebanner: 'grunt-banner'
    });
   
    var _ = require('underscore'),
        path = require('path'),
        configDir = './dev/tools/grunt/configs',
        taskDir = './dev/tools/grunt/tasks';

..........

It should resolve the issue in your Magento 2 beta version installation ..
jit-grunt: Plugin for the "xxxx" task not found.
If you have installed the plugin already, please setting the static mapping.
See https://github.com/shootaroo/jit-grunt#static-mappings

Magento 2: How to do Index Management

In Magento 2 there is no reindex button or separate reindex link to index the indices as of writing this article.
So, how can we reindex the data in Magento 2?

Well, Magento 2 comes with great CLI applications that helps us to run many tasks quickly via command line.

To reindex the indexes in Magento 2,
In command prompt navigate to the Magento 2 installation directory and then run below command.
php bin/magento indexer:reindex

If php CLI is not in your system path, one of below commands may invoke PHP CLI for you.
/usr/bin/php
/bin/php
/usr/sbin/php
/sbin/php
/usr/local/bin/php

Windows users can run
PATH_TO_php.exe bin\magento indexer:reindex   in command prompt.

Magento 2: No CSS displayed after installation

After installing Magento 2.0 framework many of us face the issue of no formatting on frontend or admin panel.
After installation there is possibility of the less files are not yet compiled and the Workflow type is server side i.e the less files should be compiled on server and your mode of project is 'developer'.
The setting is available in admin panel at Stores > Configuration > Advanced > Developer > Frontend development workflow > Workflow type.

There are two solutions.

> Set the Workflow type to "Client Side Less Compilation" but this will slow down your frontend as the less files will be compiled in browser's Javascript engine.

> The other way is to compile the files manually using the "grunt" (http://gruntjs.com/) tasks available in Magento 2. Below are the steps to follow.

1) Assuming that you have already installed nodejs (https://nodejs.org/) on the machine where the web server and your Magento 2 installation is located.
2) In the node command prompt, navigate to Magento 2 root directory and run following command to install the grunt plugin.
npm install grunt
3) The above will install the grunt npm package and you'd be now able to run grunt tasks in Magento 2 installation path.
4) Once the grunt plugin installed, run following command. You'd need your PHP process running as less compilation is executed by PHP.
grunt refresh
The above command will compile less files in all of the themes available in current installation.
It will take around 3 - 4 minutes depending on the complexity of theme. You can optionally run the following command to compile particular theme only.
grunt exec:<YOUR THEME NAME>

When the process completes successfully, you'll be able to review the frontend and admin panel with CSS formatting working.