Friday, 20 December 2019

about new GraphQL freature in Magento2

GraphQL: GraphQL is a data query language developed internally by Facebook in 2012 before being publicly released in 2015. Magento implements GraphQL to provide an alternative to REST and SOAP web APIs for frontend development.

GraphQL allows you to define the structure of the data that you need, and the server returns only the data you request. Each GraphQL-capable module contains a declarative schema that defines the syntax for queries that the module supports, as well as the attributes that can be returned. If you run a REST call such as GET /V1/products/:sku on a simple product, the system might fetch more than 100 lines of data. If all you need is the current price, the call has returned significantly more information than you need. With GraphQL, a query against the same SKU could return just the price.

You can read more details about GraphQL here.

You can check out the GraphQL tutorial here.

Let me share some useful links regarding Magento 2 GraphQL a new feature released.

=> Exaple 1

=> Example 2


Magento 2 How to add custom attribute to customer address and how to insert value in that attribute?

Magento 2 How to add a custom attribute to customer address and how to insert value in that attribute? To check the answer to the above question please click here


You can also check more Magento related Question/Answers here

Magento 2 How to duplicate the category with same structure?

I want to duplicate the category with the same structure and data.

How to duplicate child categories here? It is working correctly for a single category.

In my controller file, I have the parent category id and category id which needs to duplicate. Now how can I create duplication of a category?

Please check my code is as below:

    class DuplicateCategory extends \Magento\Backend\App\Action {
    protected $_categoryFactory;
    public function __construct(
    \Magento\Backend\App\Action\Context $context,
    \Magento\Catalog\Model\CategoryFactory $categoryFactory
    ) {
    parent::__construct($context);
    $this->_categoryFactory = $categoryFactory;
    }

    $parentCategoryObj = $this->_categoryFactory->create()->load(2);
    $duplicateCategoryObj = $this->_categoryFactory->create()->load(8);
    $catagoryObject = $this->_categoryFactory->create();

    $categoryName = $duplicateCategoryObj->getName();
    $categoryUrlKey = strtolower($this->getCategoryUrlKey($categoryName));

    $catagoryObject->setPath($parentCategoryObj->getPath())
    ->setParentId($parentCategory)
    ->setName($duplicateCategoryObj->getName())
    ->setUrlKey($categoryUrlKey)
    ->setStoreId($storeId)
    ->setIsActive(true);
    $catagoryObject->save();
    }
You can also check more Magento related Question/Answers here

Friday, 30 June 2017

Difference between Magento 1.x and 2.x

The usage of modern technologies. Magento 2.0 will be using the most recent and popular versions of PHP, particularly 5.4 and 5.5, HTML5, CSS 3.3 and the latest versions of JQuery. Differences between technologies included in Magento 1.x and 2.0 are presented in the table below.



Modified directory structure. In order to make store management quicker, Magento will reduce the number of root directories from 9 to 5. For example, the new directory “pub” will contain all the data available for publicity. This system is more convenient than previous one, where numerous files were divided among “media”, “error”, “skin”, “js”. Also, shop owners will be able to place their Magento application files outside of webserver document root.
Absent, new and changed tables in Magento 2.0. By researching the new platform’s beta version, we’ve discovered that Magento 2 doesn’t contain the following tables:
  • catalogsearch_query;
  • catalogsearch_result
  • catalog_product_enabled_index.
Also, we’ve learned that few of the tables are renamed, and some of them have more columns than before.
Renamed tables (Magento 1.x - Magento 2.0 beta):
  • core_website - store_website
  • core_store - store
  • core_translate - translation
  • core_url_rewrite - url_rewrite
  • core_store_group - store_group
  • core_email_template - email_template
  • sales_flat_order - sales_order
  • sales_flat_order_address - sales_order_address
  • sales_flat_order_grid - sales_order_grid
  • sales_flat_order_item - sales_order_item
  • sales_flat_order_payment - sales_order_payment
  • sales_flat_order_status_history - sales_order_status_history
  • coupon_aggregated_order - salesrule_coupon_aggregated_order

Wednesday, 19 April 2017

MAGENTO 2 EXTENSION INSTALLATION OVER SSH


Download extension and unzip the folder. Then move modules files to your Magento 2 root directory.

1. Connect to your magento webserver using ssh details

Run the following command in the terminal using user/password (please skip this step if you're installing expansion on the local machine) :

ssh user@domain.com

OR

ssh user@ipaddress

2. Change your current directory to Magento 2 web root directory

Command :
cd /full_path_to_magento2

3. Start setup process

Command :
php bin/magento setup:upgrade

4. Run the compiler command

Command :
php bin/magento setup:di:compile

5. Deploy static view files

Command :
php bin/magento setup:static-content:deploy


6) for reindexing
Command :
php bin/magento indexer:reindex


7) file permission change by ssh  *

find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;

chmod -R 777 pub
chmod -R 777 var

Thats all ..

Good luck.

Wednesday, 11 May 2016

MAGENTO 2.o EXTENSIONS

MAGENTO 2.o EXTENSIONS

Magento’s growing marketplace of product and services, including extensions that support Magento 2.0, help merchants do even more, with their online stores. 

click here to view magento 2 extensions

Wednesday, 17 February 2016

PHP interview questions



-What is PHP?
Ans. PHP is a recursive acronym for "PHP: Hypertext Preprocessor". PHP is a server side scripting language that is embedded in HTML. It is used to manage dynamic content, databases, session tracking, even build entire e-commerce sites.

-In how many ways you can embed PHP code in an HTML page?
Ans. All PHP code must be included inside one of the three special markup tags ate are recognised by the PHP Parser.
<?php PHP code goes here ?>
<?    PHP code goes here ?>
<script language="php"> PHP code goes here </script>
Most common tag is the <?php...?>

-Is PHP a case sensitive language?
Ans. Yes!

-types of PHP variables?
Ans. 
   Integers − are whole numbers, without a decimal point, like 4195. 
   Doubles − are floating-point numbers, like 3.14159 or 49.1. 
   Booleans − have only two possible values either true or false. 
   NULL − is a special type that only has one value: NULL. 
   Strings − are sequences of characters, like 'PHP supports string operations.' 
   Arrays − are named and indexed collections of other values. 
   Objects − are instances of programmer-defined classes, which can package up both other kinds of values and functions that are specific to the class. 
   Resources − are special variables that hold references to resources external to PHP (such as database connections).

-What is NULL?
Ans. NULL is a special type that only has one value: NULL. To give a variable the NULL value, simply assign it like this −$my_var = NULL;
The special constant NULL is capitalized by convention, but actually it is case insensitive; you could just as well have typed −$my_var = null;
A variable that has been assigned NULL has the following properties:It evaluates to FALSE in a Boolean context.It returns FALSE when tested with IsSet() function.

-What is the purpose of _CLASS_ constant?
Ans. _CLASS_ − The class name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the class name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.

-How will you find the length of a string in PHP?
Ans. <?php echo strlen("Hello world!"); ?>
 
-What is the difference between include() Function and require() Function?
Ans. If there is any problem in loading a file then the require() function generates a fatal error and halt the execution of the script whereas include() function generates a warning but the script will continue execution.
 
-How will you read a file in php?
Ans. Once a file is opened using fopen() function it can be read with a function called fread(). This function requires two arguments. These must be the file pointer and the length of the file expressed in bytes.
 
-How will you set cookies using PHP?
Ans. PHP provided setcookie() function to set a cookie. This function requires upto six arguments and should be called before <html> tag. For each cookie this function has to be called separately.
setcookie(name, value, expire, path, domain, security);
 
-What does PEAR stands for?
Ans. PEAR means “PHP Extension and Application Repository”. it extends PHP and provides a higher level of programming for web developers.
 
-How do you execute a PHP script from the command line?
Ans. ust use the PHP command line interface (CLI) and specify the file name of the script to be executed as follows: “php script.php”
 
-What is the difference between Session and Cookie?
Ans. The main difference between sessions and cookies is that sessions are stored on the server, and cookies are stored on the user’s computers in the text file format. Cookies can not hold multiple variables,But Session can hold multiple variables.We can set expiry for a cookie,The session only remains active as long as the browser is open.Users do not have access to the data you stored in Session,Since it is stored in the server.Session is mainly used for login/logout purpose while cookies using for user activity tracking.
 
-What is the use of explode() function ?
Ans. Syntax : array explode ( string $delimiter , string $string [, int $limit ] ); 

This function breaks a string into an array. Each of the array elements is a substring of string formed by splitting it on boundaries formed by the string delimiter.
 
-What is the difference between explode() and split() functions?
Ans. Split function splits string into array by regular expression. Explode splits a string into array by string.
 
-What is the use of mysql_real_escape_string() function?
Ans. It is used to escapes special characters in a string for use in an SQL statement.
 
-What is the difference between mysql_fetch_array() and mysql_fetch_assoc() ?
Ans. 
mysql_fetch_assoc function Fetch a result row as an associative array, While 
mysql_fetch_array() fetches an associative array, a numeric array, or both
 
-How do you define a constant?
Ans. Using define() directive, like define ("MYCONSTANT",150)
 
-How send email using php?
Ans. mail($to,$subject,$message,$headers);
 
-What are the encryption techniques in PHP ?
Ans. 
MD5 PHP implements the MD5 hash algorithm using the md5 function,
eg : $encrypted_text = md5 ($msg); 
mcrypt_encrypt :- string mcrypt_encrypt ( string $cipher , string $key , string $data , string $mode [, string $iv ] ); 
Encrypts plaintext with given parameters 
 
-How to delete a file from the system?
Ans. Unlink() deletes the given file from the file system.
 
-What is the use of the function htmlentities?
Ans. htmlentities Convert all applicable characters to HTML entities This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.

Friday, 12 February 2016

Magento site speed optimization with htaccess

Now a days its most important to speed up your web site for getting more customer to visit it. If its taking more time to load then may be you could lost that customer.

Here i list few points regarding speed optimization of Magento web site with "htaccess" file :

=> Use Apache mod_expires and be sure to set how long files should be cached. You could use the below code for your Apache virtualhost config
<ifmodule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 month"
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType image/x-icon "access 1 year"
</ifmodule>

=> Adjust memory limit what ever you want :
## adjust memory limit
# php_value memory_limit 64M
php_value memory_limit 256M
php_value max_execution_time 18000


=> Enable Gzip Compression with htaccess as below :
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl|asp|html)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>


=> Use Apache mod_headers as below, add it in htaccess :
<IfModule mod_headers.c>
# YEAR
<FilesMatch "\.(ico|gif|jpg|jpeg|png|flv|pdf)$">
Header set Cache-Control "max-age=29030400"
</FilesMatch>
# WEEK
<FilesMatch "\.(js|css|swf)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>
# 45 MIN
<FilesMatch "\.(html|htm|txt)$">
Header set Cache-Control "max-age=86400"
</FilesMatch>
</IfModule>

=> Add mod_deflate as below :
<IfModule mod_deflate.c>
############################################
## enable apache served files compression
## http://developer.yahoo.com/performance/rules.html#gzip

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# Insert filter on all content
SetOutputFilter DEFLATE
# Insert filter on selected content types only
#AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</IfModule>

Saturday, 6 February 2016

Magento Interview Question - Answers

1. What is Magento?

Ans. Magento is a rich-featured eCommerce platform built on open-source technology that provides online merchants with unprecedented flexibility and control over the look, content and functionality of their eCommerce store. Magentos intuitive administration interface features powerful marketing, search engine optimization and catalog-management tools to give merchants the power to create sites that are tailored to their unique business needs. Designed to be completely scalable and backed by Variens support network, Magento offers companies the ultimate eCommerce solution.



2. What architecture is used by Magento?

Ans. MVC which means Model-View-Controller.



3. How much Magento product Types?

Ans.
- Simple products
A Magento simple product is the most used product type for Magento webshops. This is because it's the most general product type of them all. A Magento simple product should be used for a single item without any specific selectable variations. Think about a coffee cup, a chandelier, a table or whatever.


- Grouped products
A Magento grouped product should be used for a combination of Magento simple products. Think about a coffee cup that is sold together with a saucer, a silver spoon, a breakfast plate or whatever. You can't define a specific price for a Magento grouped product but you can define a discount amount.


- Configurable products
A Magento configurable product should be used for a single item with specific selectable variations. Think about a coffee cup obtainable in different colours and sizes, a woman's bag obtainable in different materials, a light boll obtainable in different watts or whatever. Each selectable variation can have its own additional costs.


- Virtual products
A Magento virtual product should be used for a virtual (not touchable) item. Think about an insurance, a reservation, an extra product guarantee or whatever. A virtual product does not allow selecting a shipping method at checkout simply because there's nothing to ship.


- Bundle products
A Magento bundle product should be used for a bundle of simple (or virtual) products which are not to be sold separately. Think about a laptop where the customer can choose various items such as hard disk, processor, internal memory or whatever. Each of these items are simple (or virtual) products but can only be sold within the bundle product.


- Downloadable products
A Magento downloadable product should be used for online software items. Think about an MP3 file, a PowerPoint presentation, a Magento extension or whatever. A downloadable product does not allow selecting a shipping method at checkout simply because there's nothing to ship.



4. What are the different features of Magento?

Ans.
- User Management
- Customer Management
- Product Management
- Order Management
- Payment Management
- Site Management
- Search engine optimization
- International Support



5. What is Magento module structure?

Ans.
- app/ 1) code 2) etc
- code => local => Namespache => modulename => Block
- controllers
- etc
- Helper
- Model
- sql



6. How we can enhance the Magento performance?

Ans.
- Disable the Magento log
- Disable any un-used modules (i.e, mage_poll)
- Magento Caching ( Enable Cache for good result)
- Enable Gzip compression
- USE Gzip Components
- Optimize your images
- Optimize your Server
- Use a Content Delivery Network (CDN)
- Put Stylesheets at Top (Add CSS Files in head tag)
- Put Scripts at the Bottom (Add Js files in footer)
- Avoid CSS Expressions



7. what is the difference between Mage::getModel() and Mage::getSingletone() in Magento?

Ans.
- Mage::getModel(): It always creates a new object
- Mage::getSingleton(): It always look for an existing object and if not then creates a new object



8. What technology used by Magento?

Ans.
Magento uses PHP as a web server scripting language and the MySQL Database. The data model is based on the Entity-attribute-value model that stores data objects in tree structures, thus allowing a change to a data structure without changing the database definition.



9. How to create magento custom module?

Ans.
Steps to create custom magento module:
Namespace : Uts
Module Name : Utsmodule
- Create directory Utsmodule in app/code/local/Uts
- Create Block, controllers, etc, Utsmodule directories.( Create controller, block and module file as required.)
- Create module configuration file (app/code/local/Uts/Utsmodule/etc/config.xml).
- Create xml file (app/etc/modules/Uts_Utsmodule.xml)to enable/disable module and tell magento system from which code pool that module will be taken.



10. How to include CMS block in template file(.phtml)?

Ans.
Access block's content from .phtml template file by :
echo $this->getLayout()->createBlock('cms/block')->setBlockId('static_block_id')->toHTML();


about new GraphQL freature in Magento2

GraphQL: GraphQL is a data query language developed internally by Facebook in 2012 before being publicly released in 2015. Magento impleme...