Jump to content

Edit History

theodiablo

theodiablo

Hi there,

I have been trying for some time now to display the product variation image on the backoffice Order Detail's page in the product line.

For some reason, it prints an incorrect image and I can't make it show the correct one.

I have been trying to edit the getProducts from the AdminOrderController.php file, but it keeps showing an image from another product and I can't say why!

 

This is my code right now:

    protected function getProducts($order)
    {
        $products = $order->getProducts();

        foreach ($products as &$product) {
            $productInstance = new Product($product['product_id']);
            $combinationImages = $productInstance->getCombinationImages((int) Configuration::get('PS_LANG_DEFAULT'));
            $name = 'product_mini_' . (int) $product['product_id'] . (isset($product['product_attribute_id']) ? '_' . (int) $product['product_attribute_id'] : '') . '.jpg';
            
            $attributeImages = Image::getBestImageAttribute((int) Configuration::get('PS_SHOP_DEFAULT'), 
                                                            (int) Configuration::get('PS_LANG_DEFAULT'), 
                                                            $product['product_id'], 
                                                            $product['product_attribute_id']);
            if(!empty($attributeImages)){
                $attributeImage = new Image($attributeImages['id_image']);
                $product['image_tag'] = ImageManager::thumbnail(_PS_IMG_DIR_ . 'p/' . $attributeImage->getExistingImgPath() . '.jpg', $name, 80, 'jpg');
            
            } else
				// Previous code here
        }
    }

Here are my variations defined with the correct image associated: spacer.png

 

And as you can see here, the image displayed in the product line isn't correct: spacer.png

Here it should display the green image and not the blue one.

I have cleared cache and deleted the cached thumbnail images which I know could cause errors, but it is still happening and I can't understand why 😞 

Does anyone have this error before? How could I display the correct variation image?

Thanks.

theodiablo

theodiablo

Hi there,

I have been trying for some time now to display the product variation image on the backoffice Order Detail's page in the product line.

For some reason, it prints an incorrect image and I can't make it show the correct one.

I have been trying to edit the getProducts from the AdminOrderController.php file, but it keeps showing an image from another product and I can't say why!

 

This is my code right now:

    protected function getProducts($order)
    {
        $products = $order->getProducts();

        foreach ($products as &$product) {
            $productInstance = new Product($product['product_id']);
            $combinationImages = $productInstance->getCombinationImages((int) Configuration::get('PS_LANG_DEFAULT'));
            $name = 'product_mini_' . (int) $product['product_id'] . (isset($product['product_attribute_id']) ? '_' . (int) $product['product_attribute_id'] : '') . '.jpg';
            
            $attributeImages = Image::getBestImageAttribute((int) Configuration::get('PS_SHOP_DEFAULT'), 
                                                            (int) Configuration::get('PS_LANG_DEFAULT'), 
                                                            $product['product_id'], 
                                                            $product['product_attribute_id']);
            if(!empty($attributeImages)){
                $attributeImage = new Image($attributeImages['id_image']);
                $product['image_tag'] = ImageManager::thumbnail(_PS_IMG_DIR_ . 'p/' . $attributeImage->getExistingImgPath() . '.jpg', $name, 80, 'jpg');
            
            } else
				// Previous code here
        }
    }

Here are my variations defined with the correct image associated: spacer.png

 

And as you can see here, the image displayed in the product line isn't correct: spacer.png
I have cleared cache and deleted the cached thumbnail images which I know could cause errors, but it is still happening and I can't understand why 😞 

Does anyone have this error before? How could I display the correct variation image?

Thanks.

×
×
  • Create New...