How To

Magento 2: How To Import Products with Custom Product Type

Hello Magento Folks?,

How’s everyone doing? Welcome back to our article of How To Series for Magento 2 where we are going to understand Magento 2: How To Import Products with Custom Product Types. Previously, in our most recent article we have learned about Magento 2: How to Save Custom Attribute Value After Customer Register 

Let’s Get deep into this?

Introduction:

Basically, Magento 2 is very flexible when considered features. It has an inbuilt functionality where by default one can import and export products and many more things from the admin directly. But in condition, there are mandatory rules to follow while we are implementing the importing and exporting products in Magento 2. You can import-export products like a simple product, virtual products, etc. But in case what if you want to import products with custom product types? No worries, the below-given code will help you in importing products with custom product types.

Let’s Code It

Step 1: Firstly, we need to create  import.xml file at the following path,

app\code\Vendor\Extension\etc and add the below code

<?xml version="1.0"?> 
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_ImportExport:etc/import.xsd"> 
<entityType entity="catalog_product" name="custom_product_type_name" model="Vendor\Extension\Model\Import\Type\Producttype" /> 
</config>

Step 2: After that, we need to create a Producttype.php file inside the below path.

app\code\Vendor\Extension\Model\Import\Type and add below code

<?php 
namespace Vendor\Extension\Model\Import\Type; 
class Producttype extends \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType 
{ 
const BEFORE_OPTION_VALUE_DELIMITER = ';'; 
const PAIR_VALUE_SEPARATOR = '='; 
const VALUE_DYNAMIC = 'dynamic'; 
const VALUE_FIXED = 'fixed'; 
const NOT_FIXED_DYNAMIC_ATTRIBUTE = 'price_view'; 
const SELECTION_PRICE_TYPE_FIXED = 0; 
const SELECTION_PRICE_TYPE_PERCENT = 1; 
protected $connection; 
protected $_resource; 
protected $_cachedOptions = []; 
protected $_cachedSkus = []; 
protected $_cachedSkuToProducts = []; 
protected $_cachedOptionSelectQuery = []; 
public function isRowValid(array $rowData, $rowNum, $isNewProduct = true) 
{ 
return parent::isRowValid($rowData, $rowNum, $isNewProduct); 
} 
}

Step 3: And finally refresh the cache and start your import process with a custom product type in your CSV file inside the product_type column.

By implementing the above steps of code you will be successfully importing custom products in your Magento 2 store.

Final Words:

I hope the above solution helps you in solving your issue in importing the custom products in your Magento 2 store. If you find any difficulties in implementing the above-given solution then do contact our Support Team. If you find the article informative and knowledgeable then do share with your Magento colleagues. And do comment on your reviews in your comment section below. 

Happy Coding?

Click to rate this post!
[Total: 4 Average: 5]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

Recent Posts

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

1 day ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

1 day ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

2 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

3 days ago

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

5 days ago

How Upcoming Cookie Changes Will Affect Your E-commerce Website?

The e-commerce world is constantly in flux. New tech and strategies emerge daily to help…

5 days ago