Skip to content

Instantly share code, notes, and snippets.

@paugnu
Created November 17, 2020 20:35
Show Gist options
  • Save paugnu/ed3b10ea3d3613791c53c9e3719fce89 to your computer and use it in GitHub Desktop.
Save paugnu/ed3b10ea3d3613791c53c9e3719fce89 to your computer and use it in GitHub Desktop.
<?php
/**
* Copyright © All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Brildor\Migration\Console\Command;
use JsonMachine\JsonMachine;
use Magento\Catalog\Api\Data\ProductExtensionFactory;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\Data\ProductLinkInterface;
use Magento\Catalog\Model\ProductFactory;
use Magento\Catalog\Model\ProductLink\Link;
use Magento\Catalog\Api\ProductRepositoryInterface as ProductRepository;
use Magento\Catalog\Model\CategoryRepository;
use Magento\Eav\Api\AttributeRepositoryInterface;
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
use Magento\Catalog\Helper\Category;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\App\State;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Exception\StateException;
use Magento\Framework\Filesystem\DirectoryList;
use Magento\Setup\Exception;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Magento\Catalog\Api\AttributeSetRepositoryInterface;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
use Magento\ConfigurableProduct\Helper\Product\Options\Factory;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable\AttributeFactory;
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute as AttributeResource;
use Magento\Framework\Registry;
use Magento\Catalog\Api\Data\ProductLinkInterfaceFactory;
use function PHPUnit\Framework\throwException;
class ImportProducts extends Command
{
const FILE_OPTION = "file";
const DELETE_OPTION = "delete";
const TYPE_OPTION = "type";
private $translatedAttributes = array(
'name',
'description',
'short_description',
'meta_title',
'meta_description',
'url_key',
//'vimeo_id',
'news_from_date',
'news_to_date',
'visibility',
//'featured_product'
);
private DirectoryList $directoryList;
private ProductFactory $product;
private ProductRepository $productRepository;
private CategoryRepository $categoryRepository;
private AttributeRepositoryInterface $attributeRepository;
private SearchCriteriaBuilder $searchCriteriaBuilder;
private Category $category;
private ProductResource $productResource;
private array $categoryMapping;
private array $attributeSetsMapping;
protected AttributeSetRepositoryInterface $attributeSetRepository;
private State $state;
private Factory $optionInterface;
private ProductExtensionFactory $productExtensionFactory;
private AttributeFactory $configurableAttribute;
private AttributeResource $attributeResource;
private Configurable $configurable;
private Registry $registry;
private ProductLinkInterfaceFactory $productLinkInterface;
private int $count;
private int $countcompare;
/**
* @var ResourceConnection
*/
private ResourceConnection $resource;
/**
* ImportProducts constructor.
* @param DirectoryList $directoryList
* @param ProductFactory $product
* @param ProductRepository $productRepository
* @param CategoryRepository $categoryRepository
* @param AttributeRepositoryInterface $attributeRepository
* @param Category $category
* @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param AttributeSetRepositoryInterface $attributeSetRepository
* @param State $state
* @param ProductResource $productResource
* @param ResourceConnection $resource
* @param Factory $optionInterface
* @param ProductExtensionFactory $productExtensionFactory
* @param AttributeFactory $configurableAttribute
* @param AttributeResource $attributeResource
* @param Configurable $configurable
* @param Registry $registry
* @param ProductLinkInterfaceFactory $productLinkInterface
*/
public function __construct(
DirectoryList $directoryList,
ProductFactory $product,
ProductRepository $productRepository,
CategoryRepository $categoryRepository,
AttributeRepositoryInterface $attributeRepository,
Category $category,
SearchCriteriaBuilder $searchCriteriaBuilder,
AttributeSetRepositoryInterface $attributeSetRepository,
State $state,
ProductResource $productResource,
ResourceConnection $resource,
Factory $optionInterface,
ProductExtensionFactory $productExtensionFactory,
AttributeFactory $configurableAttribute,
AttributeResource $attributeResource,
Configurable $configurable,
Registry $registry,
ProductLinkInterfaceFactory $productLinkInterface
)
{
$this->directoryList = $directoryList;
$this->product = $product;
$this->productRepository = $productRepository;
$this->categoryRepository = $categoryRepository;
$this->attributeRepository = $attributeRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->category = $category;
$this->attributeSetRepository = $attributeSetRepository;
$this->resource = $resource;
$this->categoryMapping = $this->generateCategoryMapping();
$this->state = $state;
$this->productResource = $productResource;
$this->optionInterface = $optionInterface;
$this->productExtensionFactory = $productExtensionFactory;
$this->configurableAttribute = $configurableAttribute;
$this->attributeResource = $attributeResource;
$this->configurable = $configurable;
$this->productLinkInterface = $productLinkInterface;
$registry->register('isSecureArea', true);
$this->count = 0;
$this->countcompare = 0;
parent::__construct();
}
/**
* {@inheritdoc}
*/
protected function execute(
InputInterface $input,
OutputInterface $output
)
{
$this->state->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML);
$file = $input->getOption(self::FILE_OPTION);
$type = $input->getOption(self::TYPE_OPTION);
$dir = $this->directoryList->getRoot();
$this->attributeSetsMapping = $this->generateAttributeSetsMapping();
// Import Products if File option is provided
if (!$file || !$type) {
$output->writeln("Please provide file (-f) and type (-t) to import");
die();
} elseif ($file) {
$productsData = JsonMachine::fromFile($dir . '/' . $file);
if ($productsData) {
$this->importProducts($productsData, $type);
}
}
}
public function importProducts($productsData, $type = 'simple')
{
foreach ($productsData as $productData) {
$this->count++;
try {
//$this->productRepository->deleteById($productData['sku']);
$product = $this->productRepository->getById($productData['entity_id']);
$this->productRepository->delete($product);
echo $productData['sku'] . ' - Exists, deleted...' . "\n";//die();
} catch (StateException $e) {
} catch (NoSuchEntityException $e) {
echo $productData['sku'] . ' - Product does not exist, creating new...' . "\n";
}
echo 'Importing Product: ' . $this->count . ' - ' . $productData['sku'] . "\n";
$preparedSimpleData = $this->prepareSimpleProductData($productData);
$tierPriceOther = false;
if (isset($preparedSimpleData['tier_price'])) {
foreach ($preparedSimpleData['tier_price'] as $key => $tierPrice) {
if ($tierPrice['cust_group'] == '125') {
$preparedSimpleData['tier_price'][$key]['cust_group'] = '2'; // RCF group
} elseif ($tierPrice['cust_group'] != '32000') { // We unset other group discounts
unset($preparedSimpleData['tier_price'][$key]);
}
}
$tierPriceOther = $this->checkIfTierPriceDifferentGroup($preparedSimpleData['tier_price']);
}
if (!$tierPriceOther) {
$this->createProduct($preparedSimpleData, $productData, $type);
} else {
echo 'Product: ' . $preparedSimpleData['sku'] . " contains tier prices for group $tierPriceOther\n";
}
}
}
public function checkIfTierPriceDifferentGroup($tierPrices)
{
$result = false;
foreach ($tierPrices as $tierPrice) {
if ($tierPrice['cust_group'] != '32000' && $tierPrice['cust_group'] != '2') {
$result = $tierPrice['cust_group'];
break;
}
}
return $result;
}
public function prepareSimpleProductData($productData)
{
// Basic data
foreach ($this->getAttributeCodes() as $attributeCode) {
$attributeIndex = $attributeCode[1];
if ($attributeCode[1] == 'm1_entity_id') {
$attributeIndex = 'entity_id';
}
if (isset($productData[$attributeIndex])) {
$data[$attributeIndex] = $productData[$attributeIndex];
if ($attributeCode[1] == 'm1_entity_id') {
$data[$attributeIndex] = $productData['entity_id'];
}
if ($this->checkIfSpecialAttribute($attributeCode[0])) {
$data[$attributeCode[1]] = $this->getAttributeIdFromValue($productData[$attributeCode[1]], $attributeCode[1]);
}
}
}
// Attribute Set
$data['attribute_set_id'] = array_search($productData['attribute_set'], $this->attributeSetsMapping);
// Categories
if (isset($productData['categories'])) {
if (count($productData['categories'])) {
$data['category_ids'] = $this->getCategoriesIdsForProduct($productData['categories']);
}
}
// Media images
if (isset($data['media_gallery'])) {
foreach ($data['media_gallery']['images'] as $key => $image) {
$data['media_gallery']['images'][$key]['media_type'] = 'image';
}
}
// Stock
if (isset($productData['stock_data'])) {
$data['stock_data'] = array(
'qty' => $productData['stock_data']['qty'],
'use_config_manage_stock' => $productData['stock_data']['use_config_manage_stock'],
'manage_stock' => $productData['stock_data']['manage_stock'],
'backorders' => $productData['stock_data']['backorders'],
'is_in_stock' => $productData['stock_data']['is_in_stock'],
'use_config_backorders' => $productData['stock_data']['use_config_backorders'],
'use_config_enable_qty_inc' => $productData['stock_data']['use_config_enable_qty_inc'],
'enable_qty_increments' => $productData['stock_data']['enable_qty_increments'],
'use_config_qty_increments' => $productData['stock_data']['use_config_qty_increments'],
'qty_increments' => $productData['stock_data']['qty_increments'],
'min_sale_qty' => $productData['stock_data']['min_sale_qty'],
'use_config_min_sale_qty' => $productData['stock_data']['use_config_min_sale_qty'],
'max_sale_qty' => $productData['stock_data']['max_sale_qty'],
'use_config_max_sale_qty' => $productData['stock_data']['use_config_max_sale_qty']
);
}
if (isset($productData['translations'])) {
$data['translations'] = $productData['translations'];
}
if (isset($productData['related'])) {
$data['related'] = $productData['related'];
}
return $data;
}
public function getAttributeIdFromValue($value, $attributeCode)
{
$attribute = $this->attributeRepository->get(4, $attributeCode);
$attributeValue = '';
if (is_array($value)) {
foreach ($value as $arrayValue) {
$attributeValue .= $attribute->getSource()->getOptionId($arrayValue) . ',';
}
$attributeValue = substr($attributeValue, 0, -1);
} else {
$attributeValue = $attribute->getSource()->getOptionId($value);
}
return $attributeValue;
}
public function getCategoriesIdsForProduct($categories)
{
$categoriesArray = array();
foreach ($categories as $key => $category) {
if (isset($this->categoryMapping[$key])) {
$categoriesArray[] = $this->categoryMapping[$key];
} else {
echo 'Category ID ' . $key . ' can\'t be mapped' . "\n";
}
}
return $categoriesArray;
}
/**
* @param $data
* @param $productData
* @param $type
* @return bool
* @throws \Magento\Framework\Exception\LocalizedException
* @throws NoSuchEntityException
*/
public function createProduct($data, $productData, $type)
{
$product = $this->product->create();
$product->setData($data);
$product->setTypeId('simple');
if ($type != 'configurable' && $type != 'grouped') {
$product->setTypeId($productData['type_id']);
}
$product->setWebsiteIds(array(1));
try {
echo "Saving Product Resource \n";
$this->productResource->save($product);
if (isset($data['translations'])) {
foreach ($this->translatedAttributes as $translatedAttribute) {
$_product = $this->product->create();
$this->productResource->load($_product, $product->getId());
foreach ($data['translations'] as $storeId => $storeTranslation) {
if (isset($data['translations'][$storeId][$translatedAttribute])) {
$_product->setStoreId($storeId);
$_product->setData($translatedAttribute, $data['translations'][$storeId][$translatedAttribute]);
$this->productResource->saveAttribute($_product, $translatedAttribute);
}
}
}
}
} catch (\Exception $e) {
echo $e->getMessage();
}
echo "Product Resource Saved, now associated: \n";
if (isset($productData['configurable']) && $product->getId() && ($type == 'configurable' || $type == 'all' && $productData['type_id'] == 'configurable')) {
//echo 'Is configurable... ';
if (isset($productData['configurable']['associated'])) {
//echo 'Created product with ID: ' . $product->getId() . "\n";
foreach ($productData['configurable']['associated'] as $associated) {
//echo $associated . "\n";
$associatedProductIds[] = $this->productRepository->get($associated)->getId();
}
$product->setTypeId(Configurable::TYPE_CODE);
$attributeModel = $this->configurableAttribute->create();
$position = 0;
$attributes = array();
$attributeExistFlag = false;
foreach ($productData['configurable']['super'] as $superAttributeCode) {
$attribute = $this->productResource->getAttribute($superAttributeCode['attribute_id']);
if ($attribute) {
$attributeExistFlag = true;
$attributes[] = $attribute->getId();
$data = array('attribute_id' => $attribute->getId(), 'product_id' => $product->getId(), 'position' => $position);
$position++;
$attributeModel->setData($data)->save();
}
}
if ($attributeExistFlag) {
$product->setAffectConfigurableProductAttributes(4);
$this->configurable->setUsedProductAttributes($product, $attributes);
$product->setAssociatedProductIds($associatedProductIds);
$product->setCanSaveConfigurableAttributes(true);
$this->productResource->save($product);
}
//echo 'Saved ' . "\n";
} else {
echo 'Product: ' . $productData['sku'] . ' has no associated. Configurable kept as simple' . "\n";
}
} elseif (isset($productData['grouped']) && $product->getId() && ($type == 'grouped' || $type == 'all' && $productData['type_id'] == 'grouped')) {
$product->setTypeId($type);
echo "Product is Grouped \n";
if (isset($productData['grouped']['associated'])) {
//echo 'There are associated for the grouped product' . "\n";
foreach ($productData['grouped']['associated'] as $associated) {
//echo $associated['sku'] . "\n";
$productLink = $this->productLinkInterface->create();
$productLink->setSku($productData['sku'])
->setLinkType('associated')
->setLinkedProductSku($associated['sku'])
->setLinkedProductType('simple')
->setPosition($associated['position'])
->getExtensionAttributes()
->setQty(1);
$associatedProducts[] = $productLink;
}
$product->setProductLinks($associatedProducts);
echo "Saving associated products... \n";
$this->productRepository->save($product);
echo "Associated products saved... \n";
} else {
echo 'Product: ' . $productData['sku'] . ' has no associated. Grouped kept as simple' . "\n";
}
}
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName("brildor_migration:import_products");
$this->setDescription("Import Products from a json file");
$this->setDefinition([
new InputOption(self::FILE_OPTION, "-f", InputOption::VALUE_REQUIRED, "File name"),
new InputOption(self::TYPE_OPTION, "-t", InputOption::VALUE_REQUIRED, "Product Type")
]);
parent::configure();
}
public function getAttributeCodes()
{
return array(
'56' => array('text', 'name'),
'57' => array('textarea', 'description'),
'58' => array('textarea', 'short_description'),
'59' => array('text', 'sku'),
'60' => array('price', 'price'),
'61' => array('price', 'special_price'),
'62' => array('date', 'special_from_date'),
'63' => array('date', 'special_to_date'),
'64' => array('price', 'cost'),
'65' => array('weight', 'weight'),
'66' => array('select', 'manufacturer'),
'67' => array('text', 'meta_title'),
'68' => array('textarea', 'meta_keyword'),
'69' => array('textarea', 'meta_description'),
'70' => array('media_image', 'image'),
'71' => array('media_image', 'small_image'),
'72' => array('media_image', 'thumbnail'),
'73' => array('gallery', 'media_gallery'),
'74' => array('empty', 'old_id'),
'75' => array('text', 'tier_price'),
'76' => array('select', 'color'),
'77' => array('date', 'news_from_date'),
'78' => array('date', 'news_to_date'),
'79' => array('gallery', 'gallery'),
'80' => array('select', 'status'),
'81' => array('select', 'tax_class_id'),
'82' => array('text', 'url_key'),
'83' => array('empty', 'url_path'),
'84' => array('price', 'minimal_price'),
'85' => array('text', 'visibility'),
'86' => array('select', 'custom_design'),
'87' => array('date', 'custom_design_from'),
'88' => array('date', 'custom_design_to'),
'89' => array('textarea', 'custom_layout_update'),
'91' => array('select', 'options_container'),
'92' => array('text', 'required_options'),
'93' => array('text', 'has_options'),
'94' => array('text', 'image_label'),
'95' => array('text', 'small_image_label'),
'96' => array('text', 'thumbnail_label'),
'464' => array('select', 'gift_message_available'),
'465' => array('empty', 'price_type'),
'466' => array('empty', 'sku_type'),
'467' => array('empty', 'weight_type'),
'468' => array('select', 'price_view'),
'469' => array('empty', 'shipment_type'),
'470' => array('empty', 'links_purchased_separately'),
'471' => array('empty', 'samples_title'),
'472' => array('empty', 'links_title'),
'492' => array('multiselect', 'motivo'),
'493' => array('select', 'rango_tamanos'),
'494' => array('text', 'ancho'),
'495' => array('text', 'alto'),
'496' => array('multiselect', 'tipopiedra'),
'497' => array('text', 'fondo'),
'498' => array('text', 'metraje'),
'504' => array('select', 'page_layout'),
'509' => array('multiselect', 'ropa_temporada'),
'510' => array('multiselect', 'ropa_genero'),
'511' => array('multiselect', 'ropa_ambiente'),
'512' => array('multiselect', 'ropa_detalles'),
'515' => array('multiselect', 'ropa_composicion'),
'516' => array('multiselect', 'ropa_marcaje'),
'517' => array('select', 'ropa_gramaje'),
'523' => array('text', 'area_imprimible'),
'525' => array('multiselect', 'subli_superficie'),
'526' => array('text', 'general_medidas'),
'527' => array('multiselect', 'subli_color'),
'528' => array('multiselect', 'subli_tipo'),
'533' => array('select', 'meta_robots'),
'534' => array('text', 'created_at'),
'535' => array('text', 'updated_at'),
'538' => array('multiselect', 'acabado_transfer'),
'539' => array('select', 'grupo_precios'),
'541' => array('text', 'productsliderprio'),
'542' => array('text', 'productslideralttext'),
'543' => array('text', 'productsliderscope'),
'544' => array('text', 'descuetopdf'),
'545' => array('multiselect', 'composicion_complementos'),
'546' => array('multiselect', 'detalles_complemento'),
'550' => array('select', 'canonical_url'),
'553' => array('select', 'tension'),
'554' => array('select', 'potencia'),
'555' => array('text', 'maxima_pantalla'),
'558' => array('boolean', 'enabledesc'),
'559' => array('select', 'marca_planchas'),
'560' => array('select', 'cierre_planchas'),
'561' => array('select', 'apertura_planchas'),
'562' => array('select', 'ajuste_presion_planchas'),
'563' => array('multiselect', 'area_estampacion_planchas'),
'568' => array('select', 'is_recurring'),
'569' => array('text', 'recurring_profile'),
'577' => array('empty', 'links_exist'),
'578' => array('multiselect', 'product_payment_methods'),
'580' => array('multiselect', 'subli_talla'),
'581' => array('text', 'peso_neto'),
'582' => array('text', 'peso_bruto'),
'583' => array('multiselect', 'disponibilidad'),
'589' => array('select', 'tintas_subli_color'),
'590' => array('select', 'tinta_subli_formato'),
'591' => array('select', 'vinilo_formato'),
'592' => array('select', 'vinilo_color'),
'597' => array('select', 'perso_dimensiones'),
'598' => array('select', 'hilos_formato_bordado'),
'599' => array('text', 'hilos_color_bordado'),
'600' => array('text', 'hilos_color_hex_bordado'),
'601' => array('select', 'tinta_subli_impresora'),
'602' => array('text', 'hilos_color_coser'),
'603' => array('text', 'hilos_color_hex_coser'),
'604' => array('select', 'hilos_formato_coser'),
'605' => array('select', 'tipo_copo_personalizables'),
'607' => array('select', 'tipo_hilo'),
'608' => array('select', 'tipo_asa_person'),
'609' => array('text', 'sku_hilo_natural'),
'610' => array('text', 'sku_hilo_blanco'),
'611' => array('text', 'sku_hilo_color'),
'612' => array('select', 'acce_subli_formatao'),
'613' => array('select', 'adhe_bordado_formato'),
'615' => array('select', 'rotu_bordado_tipo'),
'616' => array('select', 'padhe_bordado_grosor'),
'617' => array('select', 'ropa_color_nuevo'),
'618' => array('select', 'ropa_talla_nuevo'),
'619' => array('select', 'perso_color'),
'620' => array('multiselect', 'ancho_corte_plotter'),
'621' => array('multiselect', 'velocidad_corte_plotter'),
'622' => array('multiselect', 'presion_corte_plotter'),
'623' => array('select', 'sensor_corte_plotter'),
'624' => array('select', 'modelo_plotter'),
'628' => array('text', 'perso_grosor'),
'629' => array('select', 'fieltro_color'),
'630' => array('select', 'fieltro_formato'),
'632' => array('select', 'consu_plotter_formato'),
'633' => array('select', 'consu_plotter_aplicacion'),
'634' => array('select', 'consu_plotter_modelo'),
'642' => array('select', 'transfer_color'),
'643' => array('select', 'transfer_tamano'),
'644' => array('select', 'transfer_numero'),
'645' => array('select', 'perso_acabado'),
'646' => array('select', 'consu_idp_tintas'),
'647' => array('select', 'consu_idp_formato'),
'649' => array('select', 'medidas_bordado'),
'650' => array('select', 'abrazaderas_tipo'),
'651' => array('select', 'perso_tipo_llavero'),
'653' => array('select', 'grosor_bordado_acces'),
'654' => array('select', 'usb_bordado_acces'),
'655' => array('select', 'garfio_tipo'),
'656' => array('select', 'superf_magica_person'),
'657' => array('select', 'sistema_agujas_bor'),
'658' => array('select', 'num_punta_agujas_bor'),
'661' => array('select', 'color_entretelas'),
'662' => array('select', 'mfs_bordado_bastidor'),
'664' => array('select', 'muestrarios_bordado_tipo'),
'665' => array('select', 'teflon_planchas'),
'666' => array('select', 'volumen_taza_person'),
'670' => array('select', 'is_imported'),
'686' => array('select', 'medida_config'),
'689' => array('select', 'pedreria_color'),
'690' => array('select', 'lentejuela_color'),
'692' => array('select', 'toners_cart_color'),
'693' => array('select', 'tintas_seri_color'),
'694' => array('select', 'formato_config'),
'696' => array('text', 'qty_multiple'),
'697' => array('select', 'trama_serig'),
'698' => array('select', 'dureza_serig'),
'699' => array('select', 'perfil_serig'),
'700' => array('multiselect', 'medidas_brazo_bastidor'),
'701' => array('select', 'tipo_config'),
'703' => array('select', 'grosor_config'),
'705' => array('text', 'super_ventas'),
'712' => array('text', 'producto_formulario'),
'715' => array('select', 'country_of_manufacture'),
'716' => array('select', 'msrp_enabled'),
'717' => array('select', 'msrp_display_actual_price_type'),
'718' => array('price', 'msrp'),
'725' => array('text', 'group_price'),
'726' => array('select', 'exclude_from_sitemap'),
'728' => array('text', 'cjm_imageswitcher'),
'729' => array('text', 'cjm_moreviews'),
'730' => array('select', 'cjm_useimages'),
'744' => array('select', 'amxnotif_hide_alert'),
'747' => array('boolean', 'presupuesto'),
'750' => array('boolean', 'show_offer_date'),
'752' => array('text', 'custom_canonical_url'),
'755' => array('multiselect', 'sm_tag_navigation'),
'757' => array('select', 'available_product'),
'758' => array('select', 'available_cart'),
'759' => array('text', 'search_boost'),
'761' => array('boolean', 'is_pattern'),
'762' => array('text', 'entry_date_1'),
'763' => array('text', 'real_entry_qty_1'),
'764' => array('text', 'entry_date_2'),
'765' => array('text', 'real_entry_qty_2'),
'766' => array('text', 'entry_date_3'),
'767' => array('text', 'real_entry_qty_3'),
'768' => array('text', 'parents_available'),
'769' => array('text', 'instagram_video_id'),
'805' => array('text', 'minimal_grouped_price'),
'808' => array('select', 'show_stock_order_message'),
'812' => array('text', 'vimeo_video_id'),
'829' => array('multiselect', 'mod_impresora_3d'),
'836' => array('select', 'garantia'),
'837' => array('text', 'max_availability_display'),
'838' => array('textarea', 'sold_along'),
'7164' => array('text', 'm1_entity_id')
);
}
public function checkIfSpecialAttribute($attributeType)
{
$isSpecial = false;
$specialAttributes = array(
'select',
'multiselect'
);
if (in_array($attributeType, $specialAttributes)) {
$isSpecial = true;
}
return $isSpecial;
}
private function generateCategoryMapping()
{
$categoryMapping = array();
$connection = $this->resource->getConnection(\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION);
$categories = $connection->fetchCol("SELECT entity_id FROM catalog_category_entity");
$oldCategoryIdAttributeId = $connection->fetchOne("SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'old_category_id'");
foreach ($categories as $categoryId) {
$oldCategoryId = $connection->fetchOne("SELECT value FROM catalog_category_entity_varchar WHERE attribute_id = '$oldCategoryIdAttributeId' AND entity_id = '$categoryId'");
$categoryMapping[$oldCategoryId] = $categoryId;
}
return $categoryMapping;
}
/**
* Generates the Attribute Set Mapping with ID and Names
*/
public function generateAttributeSetsMapping()
{
$searchCriteria = $this->searchCriteriaBuilder->create();
$attributeSets = $this->attributeSetRepository->getList($searchCriteria);
foreach ($attributeSets->getItems() as $attributeSet) {
$attributeSetsMapping[$attributeSet->getId()] = $attributeSet->getAttributeSetName();
}
return $attributeSetsMapping;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment