我想获取现有Prestashop 1.6网站产品的图像,并将其导入新的Prestashop 1.7网站中。我现在不是在谈论产品的变化/组合/偏差,而只是在谈论原始产品。
因此,鉴于以下变量,我编写了以下代码:
[$ps16ProductObject
是Prestashop 1.6的产品,由于使用Prestashop客户端而使用了Prestashop的Web服务而获得了
$prestashop17Product
(暂时不在我的代码中显示)是从Prestashop 1.6导入的Prestashop 1.7产品,它确实存在于Prestashop 1.7中(即:实际上是创建并保存在数据库中)。我想将$ps16ProductObject
的图像导入此Prestashop 1.7产品。 $prestashop17Product
是类class/Product.php
的实例,与Prestashop 1.6产品->hydrate()
水合($ps16ProductObject
)。
if(array_key_exists('images', $ps16ProductObject['product']['associations'])) {
foreach($ps16ProductObject['product']['associations']['images'] as $imagePs16Id) {
$image = new \Image();
$image->id_product = $ps16ProductObject['product']['id'];
$image->position = \Image::getHighestPosition($ps16ProductObject['product']['id']) + 1;
$image->add();
$new_path = $image->getPathForCreation();
$tmpfile = dirname( __FILE__ ) . '/../temp.jpeg';
$ps16image = $this->ps16Client->get([
'resource' => 'images/products/' . $ps16ProductObject['product']['id'] . '/' . $imagePs16Id['id']
]);
file_put_contents($tmpfile, $ps16image);
\ImageManager::resize($tmpfile, $new_path . '.jpeg');
unlink($tmpfile);
}
}
(受/controllers/admin/AdminProductsController.php
的启发)>
图像已正确保存到文件系统中,并显示在DB表image
,image_lang
,nch_image_shop
中。
问题是:当我进入PS17网站的BO中的产品表时,它“显示”图像,但它们是空的,好像无法加载。 “空”产品图片的路径为:/img/p/3/5/9/359-home_default.jpg
,并且没有任何404错误。我将此路径与手动创建的产品表的图像路径进行了比较,我的结论是该路径是完全正确的。
缺少什么,请如何纠正?
当我尝试打开/img/p/XXXX/YYYY/ZZZZ/XXXYYYYZZZ-home_default.jpg
时实际上出现404错误。
我想获取现有Prestashop 1.6网站产品的图像,并将其导入新的Prestashop 1.7网站中。我不是在谈论产品的变化/组合/偏差...
以下代码有效。使脚本起作用的重要的新部分是:
foreach ($imagesTypes as $imageType) {
\ImageManager::resize($tmpfile, $new_path . '-' . stripslashes($imageType['name']) . '.' . 'jpg', $imageType['width'], $imageType['height'], 'jpg');
if ($generate_hight_dpi_images) {
\ImageManager::resize($tmpfile, $new_path . '-' . stripslashes($imageType['name']) . '2x.' . 'jpg', (int) $imageType['width'] * 2, (int) $imageType['height'] * 2, 'jpg');
}
}