0

I have created a product programmatically, and products are uploading successfully but image is not displaying on product detail page here a screen shot. enter image description here

but image is also showing on homepage and admin area..heres a screeshot enter image description here

enter image description here

admin area showing the product image too, but not in the detail page? please suggest a solution.

  • NO hide from product page option is not checked – Jay Kapoor Aug 31 '17 at 10:26
  • then check your browser console , is it showing not found error ? might be its permission issue – Manthan Dave Aug 31 '17 at 10:27
  • customer/section/load/?sections=compare-products%2Ccustomer%2Cwishlist%2Clast-ordered-items&update_section_id=false&_=1504175276413 Failed to load resource: the server responded with a status of 400 (Bad Request) – Jay Kapoor Aug 31 '17 at 10:28
  • this is the 404 not found but i dont think its for Image error – Jay Kapoor Aug 31 '17 at 10:29
  • i ran the command and rewrite is already enabled – Jay Kapoor Aug 31 '17 at 10:39
1

There are many reasons that could be causing this issue, for ex :

  • On the Product Information page , In your admin backend, under 'Images', make sure the radio buttons have an image selected for 'Base Image', 'Small Image', 'Thumbnail', and that they aren't 'Excluded'.
  • Make sure the product images exist under /media/catalog/product/ (relative to your document root)
  • Make sure the /media directory is in your Apache web server's group. Magento also needs to be able to write to this directory, so you can run this command to set those permissions:
sudo chmod -R 775 /path/to/magento/media
  • In System->Configuration->General->Web , make sure "Base Media URL" is correct under both "Secure" and "Unsecure"
| improve this answer | |
  • i did all the steps u said but still not showing – Jay Kapoor Aug 31 '17 at 10:35
  • Check for all browsers/ check your memory limit for php_value memory_limit 256M – Rohan Hapani Aug 31 '17 at 10:43
  • Flush magento cache from admin.....If cache is enable then php bin/magento cache:clean execute this command also – Rohan Hapani Aug 31 '17 at 10:45
  • already did but got nun – Jay Kapoor Aug 31 '17 at 10:49
  • Rename the cache folder in media/catalog/product and refresh your website. – Rohan Hapani Aug 31 '17 at 10:54
1

Thanks to me i found solution, my code was $product->addImageToMediaGallery($image_path, array('image', 'small_image', 'thumbnail'),true);

i just added false, $product->addImageToMediaGallery($image_path, array('image', 'small_image', 'thumbnail'),true,false); at the end and that did the trick.

/**
     * Add image to media gallery
     *
     * @param string        $file              file path of image in file system
     * @param string|array  $mediaAttribute    code of attribute with type 'media_image',
     *                                          leave blank if image should be only in gallery
     * @param boolean       $move              if true, it will move source file
     * @param boolean       $exclude           mark image as disabled in product page view
     * @return \Magento\Catalog\Model\Product
     */
    public function addImageToMediaGallery($file, $mediaAttribute = null, $move = false, $exclude = true)
    {
        if ($this->hasGalleryAttribute()) {
            $this->getMediaGalleryProcessor()->addImage(
                $this,
                $file,
                $mediaAttribute,
                $move,
                $exclude
            );
        }

        return $this;
    }
| improve this answer | |
0

Could your mediagallery items be disabled? You can check by using a REST Client (I'm using Insomnia).

You need an API key for this. Create a new Integration in System -> Extensions -> Integrations, and activate the integration. You should receive an access token. Now prepare your REST request with the following header:

Authorization : Bearer [access-token] (fill access-token with your access token you've received.

Send a REST request to yourmagentohost.com/rest/V1/products/{sku}/media (filling in the sku)

You should receive a request like so:

[
    {
        "id": 150,
        "media_type": "image",
        "label": "Hunter Boots Black",
        "position": 0,
        "disabled": true,
        "types": [
            "image",
            "small_image",
            "thumbnail"
        ],
        "file": "\/1\/1\/11.2931.003.JPG"
    },
    {
        "id": 151,
        "media_type": "image",
        "label": "Hunter Boots Brown",
        "position": 1,
        "disabled": true,
        "types": [],
        "file": "\/1\/1\/11.2931.003-1.JPG"
    }
]

If disabled is true here, then you need to make sure to set it to false when creating the product programatically.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.