150 likes | 162 Views
<br>In order to bring in more stability to Magento 2, it integrated Service Contracts. On the other hand, Magento 2 Extension Attributes are utilized to enable customization of service contracts. This article will help you know more about extensions attributes in Magento 2.Read more...
E N D
Knowing About Magento 2 Extension Attributes in Detail • In order to bring in more stability to Magento 2, it integrated Service Contracts. On the other hand, Magento 2 Extension Attributes are utilized to enable customization of service contracts. This article will help you know more about extensions attributes in Magento 2 What are Service contracts? • Service contracts form the prime elements of Magento 2. They are basically sets of php interfaces defining some elements of a particular module. • With the creation of interfaces the contracts are defined that are categorized, implemented and followed. When you have a transparent contract it becomes easy to understand what is expected from a specific class and reach solid executions. There are plenty of benefits associated with the Service Contract system http://www.appsmarketplace.co.in/
Add new properties in M1 • In M1 adding information to quote, invoice, order, etc was the basic requirement. The simplest method to attain that was to include fields to coinciding database tables such as -sales_flat_quote and sales_flat_order and then fill it through fieldsets. <global> ... <fieldsets> <sales_convert_quote> http://www.appsmarketplace.co.in/
<your_special_attribute> <to_order>*</to_order> </your_special_attribute> </sales_convert_quote> </fieldsets> </global> • It transforms a quote field to order. This attribute then becomes the section of order class’s $_data property which can be accessed easily with $order->getYourSpecialAttribute(). http://www.appsmarketplace.co.in/
M2 point of view • As stated earlier, Magento 2 works with interface method as there will be no immediate accessor methods present which were put to use in M1. Here is the Service Contract for - Sales Order class <?php namespace Magento\Sales\Api\Data; interface OrderInterface extends \Magento\Framework\Api\ExtensibleDataInterface { ... /** * Gets the grand total for the order. * * @return float Grand total. */ http://www.appsmarketplace.co.in/
public function getGrandTotal(); /** * Gets the shipping amount for the order. * * @return float|null Shipping amount. */ public function getShippingAmount(); /** ** “Retrieve existing extension attributes object or create a new one” * * @return \Magento\Sales\Api\Data\OrderExtensionInterface|null */ public function getExtensionAttributes(); http://www.appsmarketplace.co.in/
/** * Set an extension attributes object. * * @param \Magento\Sales\Api\Data\OrderExtensionInterface $extensionAttributes * @return $this */ public function setExtensionAttributes(\Magento\Sales\Api\Data\OrderExtensionInterface $extensionAttributes); } • Yes, you will observe a plenty of getters & setters in the form of entities which are considered as data transfer items. http://www.appsmarketplace.co.in/
New attribute addition • It is not possible to edit the interface often when you wish to include a new attribute as that would affect the backward compatibility. The whole idea is to remain in coordination with service contracts. Limitations • At this stage, we need to bypass the interface because most classes continue to still extend \Magento\Catalog\Model\AbstractModel but don’t carry out over one reason. • In case you set a different preference for this particular service contract then your code will break • The change remains undocumented as it is based on magic • Then what is the best method to add new attributes in a modest manner that works well with the interfaces’ limitations. http://www.appsmarketplace.co.in/
Understanding Extension attributes • Just observe the other end of your interface and here are the two methods /** * Retrieve existing extension attributes object or create a new one. * * @return \Magento\Sales\Api\Data\OrderExtensionInterface|null */ public function getExtensionAttributes(); /** * Set an extension attributes object. http://www.appsmarketplace.co.in/
* * @param \Magento\Sales\Api\Data\OrderExtensionInterface $extensionAttributes * @return $this */ public function setExtensionAttributes(\Magento\Sales\Api\Data\OrderExtensionInterface $extensionAttributes); • Extension attributes are Magento 2’s aspects to offer increased stability and customisability too. http://www.appsmarketplace.co.in/
Types of attributes and features • Custom and Entity-Attribute-Value (EAV) attributes • Custom attributes are the ones added on the merchant’s behalf. The merchant can easily add the attributes using the Admin panel in Magento. Custom attributes are part of EAV attributes • Objects that utilize EAV attributes basically store values in different MySQL tables. The Customer & Catalog modules are known as the primary models that utilize EAV attributes. Other modules, like GiftMessage, ConfigurableProduct, and Tax, make use of EAV functionality for Catalog. Extension attributes • Extension attributes are basically newly introduced elements in Magento 2. They are utilized to extend functionality as well they make use of a complex set of data types rather than the custom attributes. You will not find these attributes in the Magento Admin. http://www.appsmarketplace.co.in/
Conclusion • Certainly, the efforts involved for extension attributes in Magento 2 are more than in Magento, then, you may ask why should you go for it? • The changes that come with extension attributes on service contracts are far ahead in terms of stability of the platform while attaining extensibility. Also, there are a number of benefits you can reap in using extension attributes. The benefits include the automatic availability of attribute data added through API requests. http://www.appsmarketplace.co.in/
Read the complete story follow the link below:- Knowing About Magento 2 Extension Attributes in Detail Read Blog: http://www.appsmarketplace.co.in/blog/ http://www.appsmarketplace.co.in/
Certified Magento 2 Developers We offers to hire Magento developer services in Worldwide that can address all your customized Magento needs and provide best of ecommerce solutions to them. With years of experience and expertise in the field of PHP based ecommerce open source platform, we bet our services would make your online business achieve new heights of success and recognition. By hiring dedicated Magento developer for your project, you would save on in-house resource costs with zero headache of how to extract the desired result from the developer. http://www.appsmarketplace.co.in/
LET'S GET TOGETHER Pick Right Magento 2 Extensions & Boost Your Store Performance Hassle-free One Stop Solutions, Reach Us Today! Website: http://www.appsmarketplace.co.in/ Call: +91 7096620202