hello! i have the following situation: i have to migrate a cscart store to wordpress, i migrated the products all good and nice, but the problem appeared at the images import. the situation is the following: i know that product images are stored in public_html/images/detailed but i need to understand the logic so I can create the path to the images. as i saw on the forum, the first 1 or 2 numbers from detailed_id means the folder destination, but the rest of them, what do they mean? I’m sure it has to be related to cscart_images table where the file name is stored but i dont understand the logic. can anyone help me understand this?
Why do you specifically need detailed_id field for this operation? From what I understand, you can use just object_id and object_type to identify that given image is assigned to the given product.
You can try this formula to find out the path:
./images/detailed/$path/$image_path
Where:
$path = $object_type . '/' . floor($image_id / MAX_FILES_IN_DIR);
$object_type
- Type: detailed
, blog
, logos
, etc.
$image_id
- is the value from the image_id
column in the cscart_images
table.
$image_path
- is the value from the image_path
column in the cscart_images
table.
So basically this is the code that i tried to use in order to fetch the images into woocommerce but no image was transferred:
$result = $cs_conn->query($sql);
echo “”;
echo "Products found to be transfered ".$result->num_rows;
if ($result && $result->num_rows > 0) {
echo “Found products: “.$result->num_rows.”
\n”;
while ($row = $result->fetch_assoc()) {
$product = $row;
// SQL to fetch images for the current product
$sql_images = "SELECT * FROM cscart_images_links
JOIN cscart_images ON cscart_images_links.image_id = cscart_images.image_id
WHERE cscart_images_links.object_type = 'product'
AND cscart_images_links.object_id = " . intval($row['product_id']);
$sql_images = "SELECT * FROM cscart_images_links
JOIN cscart_images ON cscart_images_links.detailed_id = cscart_images.image_id
WHERE cscart_images_links.object_type = 'product'
AND cscart_images_links.object_id = " . intval($row['product_id']);
$result_images = $cs_conn->query($sql_images);
$images = [];
while ($image_row = $result_images->fetch_assoc()) $images[] = $image_row;
echo "Images: ".count($images)."<br>\n";
echo "Product id = {$row['product_id']}<br>\n";
print_r($images);
print_r($product);
die();
// Add images to the current product
$product['images'] = $images;
// Add the current product to the all_products array
$all_products[] = $product;
}
}
Please also note that the default value of the MAX_FILES_IN_DIR constant is 1000
Why not just export the Detailed image URL then use the URL to import into Wordpress?
Yes, the problem is not when it comes to assigning to a product, the problem is to create the path to the image.
What do you exactly mean with that?
If you export the “Detailed image URL” you will have the path to the image.