在Magento2,我与不同的SKU有相同的名称产品,但当我使用Magento 2号文字时,由于Url Key,出现了错误:
<编码> Uncault PDOException:STATE[23,000]:廉正制约因素:1062 Duplicate entry reine-de-naples-jour-nuit-8998.html-1 for key URL_REITE_RE RequestST_PATH_STORE_ID
我的文字是我们用于在方案上拯救产品的内容。
<?php
use MagentoFrameworkAppBootstrap;
include( app/bootstrap.php );
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$objectManager1 = MagentoFrameworkAppObjectManager::getInstance();
$directoryList = $objectManager1->get( MagentoFrameworkAppFilesystemDirectoryList );
$path = $directoryList->getPath( media );
//var_dump($path); die;
$state = $objectManager->get( MagentoFrameworkAppState );
$state->setAreaCode( frontend );
$myarray = glob("Book2.csv");
usort($myarray, create_function( $a,$b , return filemtime($a) - filemtime($b); ));
if(count($myarray)){
/*This will create an array of associative arrays with the first row column headers as the keys.*/
$csv_map = array_map( str_getcsv , file($myarray[count($myarray)-1]));
array_walk($csv_map, function(&$a) use ($csv_map) {
$a = array_combine($csv_map[0], $a);
});
array_shift($csv_map); # remove column header
/*End*/
$message = ;
$count = 1;
foreach($csv_map as $data){
//echo <pre> ;print_r($data);exit;
$product = $objectManager->create( MagentoCatalogModelProduct );
$product->setName(trim($data[ Name ]));
$product->setTypeId( simple );
$product->setAttributeSetId(4);
$product->setSku(trim($data[ model_no ]));
$product->setURL(trim($data[ Name ]).trim($data[ model_no ]));
$product->setWebsiteIds(array(1));
$product->setVisibility(4);
$product->setCreatedAt(strtotime( now ));
$product->setPrice(trim($data[ price ]));
//$_product->setShortDescription(trim($data[ Short Description ])); // add text attribute
//$_product->setDescription(trim($data[ Long Description ])); // add text attribute
$img_url = trim($data[ img_big ]);
//$lastWord = substr($img_url, strrpos($img_url, / ) + 1);
//copy($img_url, pub/media/product/ );
$dir = $directoryList->getPath( media ). /big/ ;
$imgpath = $dir.$img_url;
//echo $imgpath; die;
/*$_product->addImageToMediaGallery($imgpath, array( image , thumbnail , small_image ), false, false); */
$product->addImageToMediaGallery($imgpath, array( image , small_image , thumbnail ), false, false);
//$_product->setImage($imgpath);
//$_product->setSmallImage($imgpath);
//$_product->setThumbnail($imgpath);
$product->setStockData(array(
use_config_manage_stock => 0, // Use config settings checkbox
manage_stock => 1, //manage stock
min_sale_qty => 1, //Minimum Qty Allowed in Shopping Cart
max_sale_qty => 2, //Maximum Qty Allowed in Shopping Cart
is_in_stock => 1, //Stock Availability
qty => 100 //qty
)
);
$product->save();
}
echo success ;
}
?>
请建议如何用乌尔尔语补充说明我的文字,在不使用同一名称的情况下罚款。