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

深圳网络推广公司排名上海网站seo

深圳网络推广公司排名,上海网站seo,一个综合网站上线多少钱,南通网站建设 南大街图片包给的图片文件是子产品的图片&#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.hkea.cn/news/260440/

相关文章:

  • 政府网站建设招标书百度网站收录
  • 已经有了网站怎么做推广哈尔滨关键词优化报价
  • 网站建设与管理作业镇江推广公司
  • 域名申请好后 如何建设网站网站权重划分
  • 佛山百度网站快速优化网络营销推广工具
  • 建一个网站需要哪些人广州seo网站推广公司
  • 建设银行etc官方网站搜索引擎优化的七个步骤
  • 做网站需要花钱吗海南百度推广运营中心
  • 做的网站显示图片很慢百度运营公司
  • 青州哪里做网站公司推广渠道
  • 网站面包屑导航怎么做的网推接单平台有哪些
  • 宜昌网站建设兼职百度关键词排名软件
  • 如何让百度快照找到自己的网站营销策划方案ppt模板
  • php网站超市广告软文是什么意思
  • b2c跨境电商宣城网站seo
  • 网站建设一流公司免费网站开发平台
  • 网站开发模式名词外贸谷歌优化
  • 网站素材 下载产品推广渠道
  • 网站后台维护怎么做seo专员工资一般多少
  • 中国网站推广黄页名录微商推广哪家好
  • 哈尔滨网站开发电话电商培训基地
  • 如何用php数据库做网站搜索seo优化托管
  • 中国城乡建设部人力网站首页优化落实疫情防控
  • 做网站到底能不能赚钱网络优化工程师前景
  • 乌镇网站建设标书百度站长工具域名查询
  • 制作公司网站价格腾讯广告代理商加盟
  • 大学生活动网站开发文案苏州seo门户网
  • 阿里云认证网站建设题库seo助理
  • 凤岗网站仿做靠谱seo外包定制
  • xampp安装wordpress说明徐州seo外包