当前位置: 首页 > wzjs >正文

建站公司用的开源系统培训课程名称大全

建站公司用的开源系统,培训课程名称大全,做任务得钱的网站,新闻宣传培训网站内容建设图片包给的图片文件是子产品的图片&#xff0c;如下图&#xff1a;A104255是主产品的sku <?php/*** 根据图片包导入产品图片&#xff0c;包含子产品和主产品* 子产品是作为主图&#xff0c;主产品是作为附加图片*/use Magento\Framework\App\Bootstrap;include(../app/boot…

图片包给的图片文件是子产品的图片,如下图:A104255是主产品的sku

<?php/*** 根据图片包导入产品图片,包含子产品和主产品* 子产品是作为主图,主产品是作为附加图片*/use Magento\Framework\App\Bootstrap;include('../app/bootstrap.php');
$bootstrap = Bootstrap::create(BP, $_SERVER);$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
/** @var \Magento\Framework\App\ResourceConnection $resource */
$resource = $objectManager->get('\Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection(\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION);$directory = $objectManager->get('\Magento\Framework\Filesystem\DirectoryList');$obj = $bootstrap->getObjectManager();$state = $obj->get('Magento\Framework\App\State');
$state->setAreaCode('adminhtml');/** @var  \Magento\Catalog\Model\ProductFactory $productFactory */
$productFactory = $objectManager->create('\Magento\Catalog\Model\ProductFactory');/** @var  \Magento\Catalog\Model\ResourceModel\MediaImageDeleteProcessor $mediaImageDeleteProcessor */
$mediaImageDeleteProcessor = $objectManager->create('\Magento\Catalog\Model\ResourceModel\MediaImageDeleteProcessor');$imageFolder = $directory->getRoot().'/pub/media/images_import';
$delUrl = $directory->getRoot().'/pub/media/catalog/product';$existsSku = [];try {// 指定搜索的文件夹和文件名进行搜索$folder = $imageFolder;//$fileName = $sku;$fileName = '*.jpg';// 执行搜索并获取结果数组$imgfiles = searchImagesInFolder($folder, $fileName);//print_r($imgfiles);die;if ($imgfiles) {foreach ($imgfiles as $imgfile) {try {$mainImagePath = $imgfile;if(is_file($mainImagePath)){$pathArr = explode('/', $mainImagePath);$imgName = end($pathArr);$sku = explode('.', $imgName)[0];if (in_array($sku, $existsSku)) continue;//if ($sku != 'B302170-5g') continue;//var_dump($sku);die;$sql = $connection->select()->from('catalog_product_entity')->where('sku = ?', $sku);$row = $connection->fetchRow($sql);if (!$row) {echo $sku,' 不存在',PHP_EOL;continue;}$product = $productFactory->create()->loadByAttribute('sku',$sku);$rowId = $product->getRowId();if (strstr($sku, '-')){ #主图#删除原有的图片/*$del = $connection->fetchAll("SELECT * from catalog_product_entity_media_gallery where value_id in( select value_id from catalog_product_entity_media_gallery_value_to_entity where row_id='{$rowId}')");foreach ($del as $key=>$value){if (file_exists($delUrl.'/'.$value['value'])) {unlink($delUrl . '/' . $value['value']);}}# 删除产品和图片的关联关系$connection->query("delete from catalog_product_entity_media_gallery where value_id in( select value_id from catalog_product_entity_media_gallery_value_to_entity where row_id='{$rowId}')");$connection->query("delete from catalog_product_entity_media_gallery_value_to_entity where row_id='{$rowId}'");$connection->query("delete from catalog_product_entity_varchar where row_id='{$rowId}' and attribute_id in(87,88,89)");*/echo $sku,' 主图',PHP_EOL;$product->setStoreId(0)->addImageToMediaGallery($mainImagePath, array('image', 'small_image', 'thumbnail'), false, false);}$product->save();#作为主产品的附加图$sku_master = explode('-', $sku)[0] ?? '';
//                    var_dump($sku_master);die;if (!$sku_master) continue;if (in_array($sku_master, $existsSku)) continue;$sql = $connection->select()->from('catalog_product_entity')->where('sku = ?', $sku_master);$row = $connection->fetchRow($sql);if (!$row) {echo $sku_master,' 不存在',PHP_EOL;continue;}$product_master = $productFactory->create()->loadByAttribute('sku',$sku_master);$rowId = $product_master->getRowId();#主产品导完删除图片$product_master->setStoreId(0)->addImageToMediaGallery($mainImagePath, [], true, false);$product_master->save();echo $sku_master,' 子图',PHP_EOL;}else{echo $sku." skip\n";}} catch (\Exception $e){throw new Exception($e->getMessage());}}} else {echo "没有找到匹配的文件。",PHP_EOL;}} catch (\Exception $e){echo $e->getMessage(),PHP_EOL;
}
//    }
//}function searchImagesInFolder($folder, $fileName)
{// 检查文件夹是否存在if (!is_dir($folder)) {return [];}// 初始化结果数组$result = [];// 打开文件夹$handle = opendir($folder);// 遍历文件夹中的文件和子文件夹while (($file = readdir($handle)) !== false) {if ($file != '.' && $file != '..') {$path = $folder . DIRECTORY_SEPARATOR . $file;// 如果是文件夹,则递归调用自身进行进一步搜索if (is_dir($path)) {$result = array_merge($result, searchImagesInFolder($path, $fileName));} else {// 如果是图片文件并且文件名与模糊匹配成功,则将文件路径添加到结果数组中if (isImageFile($file) && fnmatch("*{$fileName}*", $file)) {$result[] = $path;}}}}// 关闭文件夹closedir($handle);return $result;
}// 检查文件是否为图片文件
function isImageFile($file)
{$imageExtensions = ["jpg", "jpeg", "png", "gif"];$fileExtension = pathinfo($file, PATHINFO_EXTENSION);return in_array($fileExtension, $imageExtensions);
}

http://www.dtcms.com/wzjs/309135.html

相关文章:

  • 广州网站整站优化百度指数预测
  • asp网站安全吗深圳网络推广建站
  • 国外优秀vi设计网站百度推广客服
  • 河池网站建设公司网络营销推广8种方法
  • 机票网站制作成品网站源码在线看
  • 网站适配手机怎么做国内最新十大新闻
  • xampp可以做网站吗手机优化软件排行
  • 自己注册公司网站系统优化app
  • 网站建设与网络推广360搜索指数
  • 做甜品网站广告推广软文案例
  • 网站不备案可以做百度推广吗免费crm客户管理系统
  • 做网站一般用什么程序最新热点新闻
  • 做外贸有哪些免费的网站手机广告推广软件
  • 济南市疫情最新消息专业百度seo排名优化
  • 网站服务器自己搭建全球搜官网
  • 建设网站的服务宗旨seo优化销售话术
  • 衢州高端网站建设陕西seo排名
  • wordpress 地址 固定seo实战培训费用
  • 网站首页的概念ciliba磁力搜索引擎
  • 网络宣传网站建设建站百度快速收录工具
  • 百度不收录网站关键词泰安百度推广电话
  • 南京网站建设要多少钱seo的英文全称是什么
  • 大连关键词快速排名临沂seo推广外包
  • 新兴县城乡建设局网站中国培训网的证书含金量
  • 免费进入正能量的网站十大技能培训机构排名
  • 有什么推荐做简历的网站百度小说搜索热度排行榜
  • 网站建设手机端官网second是什么意思
  • 网站可以用cdr做吗网络营销推广策划
  • 装饰公司响应式网站建设案例河南网站关键词优化
  • 不懂网站怎么做平台高端网站定制设计