<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>XML &#8211; MeghRaj TechnoSoft &#8211; Web, App, E-commerce Development  Agency In India.</title>
	<atom:link href="https://www.meghrajtechnosoft.com/xml/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.meghrajtechnosoft.com</link>
	<description></description>
	<lastBuildDate>Mon, 07 Dec 2020 10:13:35 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.5.15</generator>

<image>
	<url>https://www.meghrajtechnosoft.com/wp-content/uploads/2020/10/fevecon.png</url>
	<title>XML &#8211; MeghRaj TechnoSoft &#8211; Web, App, E-commerce Development  Agency In India.</title>
	<link>https://www.meghrajtechnosoft.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to Create Custom Product Type in Magento 2</title>
		<link>https://www.meghrajtechnosoft.com/how-to-create-custom-product-type-in-magento-2/</link>
					<comments>https://www.meghrajtechnosoft.com/how-to-create-custom-product-type-in-magento-2/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 07 Dec 2020 07:50:50 +0000</pubDate>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[XML]]></category>
		<guid isPermaLink="false">https://www.meghrajtechnosoft.com/?p=17457</guid>

					<description><![CDATA[<p>Magento 2 supports 6 product types by default:&#160;Simple Product, Grouped Product Configurable Product, Bundle Product, Virtual Product, and Downloadable Product. These product types, each having its own features, enables Magento 2 to support a wide range of industries. However, owing [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.meghrajtechnosoft.com/how-to-create-custom-product-type-in-magento-2/">How to Create Custom Product Type in Magento 2</a> appeared first on <a rel="nofollow" href="https://www.meghrajtechnosoft.com">MeghRaj TechnoSoft - Web, App, E-commerce Development  Agency In India.</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Magento 2 supports 6 product types by default:&nbsp;Simple Product, Grouped Product Configurable Product, Bundle Product, Virtual Product, and Downloadable Product. These product types, each having its own features, enables Magento 2 to support a wide range of industries.</p>



<p>However, owing to diverse Magento areas, the need may arise to&nbsp;<em><strong>create custom product type in Magento 2</strong></em>&nbsp;to satisfy the requirements of the store to implement specific features.</p>



<p>Magento 2 allows customization to create your own complete new Magento 2 product type! Isn’t it a powerful feature for the developer?&nbsp;?</p>



<p>No worries now when a client comes with weird requirements that the default product types can’t fulfill because now you are going to learn the easy method to&nbsp;<em><strong>create custom product type in Magento 2</strong></em>. Yaay!&nbsp;?</p>



<h4 id="h-method-to-create-custom-product-type-in-magento-2">Method to Create Custom Product Type In Magento 2:</h4>



<p>1.create a&nbsp;<strong class="">product_types.xml</strong>&nbsp;file in&nbsp;<strong>etc</strong>&nbsp;folder</p>



<pre><code><?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Catalog:etc/product_types.xsd">
    <type name="generic" label="Generic Product" modelInstance="Vendor\Extension\Model\Product\Type\Generic" indexPriority="100" sortOrder="10">
        <customAttributes>
            <attribute name="refundable" value="true"/>
        </customAttributes>
    </type>
    <composableTypes>
        <type name="generic" />
    </composableTypes>
</config></code></pre>



<p>2.create&nbsp;<strong>Generic.php</strong>&nbsp;at&nbsp;<strong>Model/Product/Type/&nbsp;</strong>directory</p>



<pre><code><?xml version="1.0"?>
namespace Vendor\Extension\Model\Product\Type;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Type\AbstractType;
class Generic extends AbstractType
{
    const TYPE_CODE = 'generic';
    public function deleteTypeSpecificData(Product $product)
    {
    }
}</code></pre>



<p>3.create&nbsp;<strong>catalog_product_view_type_generic.xml</strong>&nbsp;file at&nbsp;<strong>view/frontend/layout/</strong>&nbsp;folder</p>



<pre><code><?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body/>
</page></code></pre>



<p>With the above method, you no longer need to turn down the client with limited product types! You can always create one for yourself ?</p>



<p>Get started today! If you face any doubts midway, I’m here to help you out. Just post your doubts in the Comments section below.?</p>



<p>Reward the post with 5 stars if it helped you create your custom product type!&nbsp;?</p>



<p>Thank You!</p>



<p></p>
<p>The post <a rel="nofollow" href="https://www.meghrajtechnosoft.com/how-to-create-custom-product-type-in-magento-2/">How to Create Custom Product Type in Magento 2</a> appeared first on <a rel="nofollow" href="https://www.meghrajtechnosoft.com">MeghRaj TechnoSoft - Web, App, E-commerce Development  Agency In India.</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.meghrajtechnosoft.com/how-to-create-custom-product-type-in-magento-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Add Magento 2 Configurable Products Programmatically to Cart</title>
		<link>https://www.meghrajtechnosoft.com/how-to-add-magento-2-configurable-products-programmatically-to-cart/</link>
					<comments>https://www.meghrajtechnosoft.com/how-to-add-magento-2-configurable-products-programmatically-to-cart/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Wed, 04 Nov 2020 10:12:21 +0000</pubDate>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[XML]]></category>
		<guid isPermaLink="false">https://www.meghrajtechnosoft.com/?p=16774</guid>

					<description><![CDATA[<p>A quick method for developers who get bored to check the functionalities they implement! (including me 😉) I was working on a module development task that required to check each and every feature with a simple product and configurable product. [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.meghrajtechnosoft.com/how-to-add-magento-2-configurable-products-programmatically-to-cart/">How to Add Magento 2 Configurable Products Programmatically to Cart</a> appeared first on <a rel="nofollow" href="https://www.meghrajtechnosoft.com">MeghRaj TechnoSoft - Web, App, E-commerce Development  Agency In India.</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>A quick method for developers who get bored to check the functionalities they implement! (including me 😉)</p>



<p>I was working on a module development task that required to check each and every feature with a simple product and configurable product. Each time repeating the process to select the options, add to cart, and checkout was not feasible.</p>



<p>Hence, I came up with a solution that allowed me to&nbsp;<em><strong>add Magento 2 configurable products programmatically to cart</strong></em>&nbsp;which reduced my tedious task!</p>



<p>Sharing the solution for my readers,</p>



<h4 id="h-steps-to-add-magento-2-configurable-products-programmatically-to-cart"><strong><sup>Steps to Add Magento 2 Configurable Products Programmatically to Cart:</sup></strong></h4>



<ol><li> Create&nbsp;<strong>registration.php</strong>&nbsp;file in&nbsp;<em><em><strong>app\code\[Vendor]\[Namespace]\</strong></em></em></li></ol>



<pre><code><?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    '[Vendor]_[Namespace]',
    __DIR__
);
</code></pre>



<p>     2. Create&nbsp;<strong>module.xml</strong>&nbsp;file in&nbsp;<em><em><strong>app\code\[Vendor]\[Namespace]\etc</strong></em></em></p>



<pre><code><?php
<?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="[Vendor]_[Namespace]" setup_version="1.0.0"/>
</config>
</code></pre>



<p>     3. Create&nbsp;<strong>Data.php</strong>&nbsp;file in&nbsp;<em><strong>app\code\[Vendor]\[Namespace]\Helper</strong></em></p>



<pre><code><?php
namespace [Vendor]\[namespace]\Helper;
 
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Checkout\Model\Cart;
use Magento\Catalog\Model\ProductFactory;
 
class Data extends AbstractHelper
{
    private $cart;
    private $productFactory;
    public function __construct(Context $context, Cart $cart, ProductFactory $productFactory)
    {
 
        $this->productFactory = $productFactory;
        $this->cart = $cart;
        parent::__construct($context);
 
    }
 
    public function getAddConfigurableProduct($parentId, $childId)
    {
        $parent = $this->productFactory->load($parentId);
        $child = $this->productFactory->load($childId);
 
        $cart = $this->cart;
 
        $params = [];
        $params['product'] = $parent->getId();
        $params['qty'] = '1';
        $options = [];
 
        $productAttributeOptions = $parent->getTypeInstance(true)->getConfigurableAttributesAsArray($parent);
 
        foreach ($productAttributeOptions as $option) {
            $options[$option['attribute_id']] = $child->getData($option['attribute_code']);
        }
        $params['super_attribute'] = $options;
 
        /*Add product to cart */
        $cart->addProduct($parent, $params);
        $cart->save();
 
    }
}
</code></pre>



<p>You can use the above helper method by passing parent product id and child product id in anywhere in Magento 2.</p>



<p>That’s it.</p>



<p>Whenever you are required to add configurable products to the cart while Magento 2 development, you may use this programmatic method!</p>



<p>Bookmark this post and save yourself from the tiresome task forever!</p>



<p>Hope it helps. You may use the Comments section below to mention the doubts on the topic.</p>



<p>Thank you!</p>
<p>The post <a rel="nofollow" href="https://www.meghrajtechnosoft.com/how-to-add-magento-2-configurable-products-programmatically-to-cart/">How to Add Magento 2 Configurable Products Programmatically to Cart</a> appeared first on <a rel="nofollow" href="https://www.meghrajtechnosoft.com">MeghRaj TechnoSoft - Web, App, E-commerce Development  Agency In India.</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.meghrajtechnosoft.com/how-to-add-magento-2-configurable-products-programmatically-to-cart/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Add Product to Cart Programmatically With Custom Options in Magento 2</title>
		<link>https://www.meghrajtechnosoft.com/how-to-add-product-to-cart-programmatically-with-custom-options-in-magento-2/</link>
					<comments>https://www.meghrajtechnosoft.com/how-to-add-product-to-cart-programmatically-with-custom-options-in-magento-2/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Wed, 04 Nov 2020 10:03:16 +0000</pubDate>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[XML]]></category>
		<guid isPermaLink="false">https://www.meghrajtechnosoft.com/?p=16772</guid>

					<description><![CDATA[<p>Earlier, I showed you&#160;How to Add Magento 2 Configurable Products Programmatically to Cart Now, what if you are required to&#160;add product to cart programmatically with custom options in Magento 2 ? Crazy business requirements, isn’t it?&#160;😰 I get you, fellow [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.meghrajtechnosoft.com/how-to-add-product-to-cart-programmatically-with-custom-options-in-magento-2/">How to Add Product to Cart Programmatically With Custom Options in Magento 2</a> appeared first on <a rel="nofollow" href="https://www.meghrajtechnosoft.com">MeghRaj TechnoSoft - Web, App, E-commerce Development  Agency In India.</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Earlier, I showed you&nbsp;<a rel="noreferrer noopener" href="https://meetanshi.com/blog/add-magento-2-configurable-products-to-cart?utm_source=blog&amp;utm_medium=link" target="_blank">How to Add Magento 2 Configurable Products Programmatically to Cart</a></p>



<p>Now, what if you are required to&nbsp;<em><strong>add product to cart programmatically with custom options in Magento 2</strong></em> ?</p>



<p><strong>Crazy business requirements, isn’t it?</strong>&nbsp;😰</p>



<p><strong>I get you, fellow developers</strong> 😄</p>



<p><strong>Moreover, this solution can also be helpful if you want an automatic “add to cart” functionality for the configurable product with custom options. For example, the store is offering a free product with a particular product,&nbsp;attach a warranty, or add a gift product!</strong></p>



<p><strong>But what if such products you are adding to the Magento 2 cart are the configurable product! And, if that was not enough, they have custom options too!&nbsp;It can be a bit tricky.</strong></p>



<p><strong><span class="has-inline-color has-black-color">Create&nbsp;Data.php&nbsp;file in&nbsp;<em><em>app\code\[Vendor]\[Namespace]\Helper</em></em></span></strong></p>



<p><strong>Create&nbsp;<strong>registration.php</strong>&nbsp;file in&nbsp;<em><em><strong>app\code\[Vendor]\[Namespace]\</strong></em></em></strong></p>



<pre><code><?php
    \Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    '[Vendor]_[Namespace]',
    __DIR__
 );</code></pre>



<p><strong>Create&nbsp;<strong>module.xml</strong>&nbsp;file in&nbsp;<em><em><strong>app\code\[Vendor]\[Namespace]\etc</strong></em></em></strong></p>



<pre><code><?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="[Vendor]_[Namespace]" setup_version="1.0.0"/>
</config></code></pre>



<p><strong>Here’s the solution for the same:</strong></p>



<pre><code><?php
 
namespace [Vendor]\[namespace]\Helper;
 
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Checkout\Model\Cart;
use Magento\Catalog\Model\ProductFactory;
 
class Data extends AbstractHelper
{
    private $cart;
    private $productFactory;
    
    public function __construct(Context $context, Cart $cart, ProductFactory $productFactory)
    {
 
        $this->productFactory = $productFactory;
        $this->cart = $cart;
        parent::__construct($context);
 
    }
 
    public function getAddCustomProduct($productId)
    {
        $product = $this->productFactory->load($productId);
 
        $cart = $this->cart;
 
        $params = array();
        $options = array();
        $params['qty'] = 1;
        $params['product'] = $productId;
 
        foreach ($product->getOptions() as $o) {
            foreach ($o->getValues() as $value) {
                $options[$value['option_id']] = $value['option_type_id'];
 
            }
        }
        $params['options'] = $options;
        $cart->addProduct($product, $params);
        $cart->save();
 
 
    }
}</code></pre>
<p>The post <a rel="nofollow" href="https://www.meghrajtechnosoft.com/how-to-add-product-to-cart-programmatically-with-custom-options-in-magento-2/">How to Add Product to Cart Programmatically With Custom Options in Magento 2</a> appeared first on <a rel="nofollow" href="https://www.meghrajtechnosoft.com">MeghRaj TechnoSoft - Web, App, E-commerce Development  Agency In India.</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.meghrajtechnosoft.com/how-to-add-product-to-cart-programmatically-with-custom-options-in-magento-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
