2

I have a bit customized magento gallery and only now I've spotted that no image is displayed when the product doesn't contain an image.

How can I call a Magento product image placeholder if the product has no images??

I'm fairly new to magento and can't figure it out...

I've added the ProductRibbon plugin to all my images, for client to see clearly that the product is new or not...

Thanks,

Here is the code:

<?php
    $_product = $this->getProduct();
    $_helper = $this->helper('catalog/output');
?>

<?php        
if(Mage::getStoreConfig('productribbon/mconnectgeneral/module_enable_disable'))
{ ?>
<link type="text/css" rel="stylesheet" href="<?php echo $this->getSkinUrl('css/mconnect/productribbon/mconnectproductribbon.css');?>" />    
<?php    
            //$_product = Mage::registry('current_product');
            $productViewSku = $_product->getSku(); 
            //var_dump($productViewSku);

            //exit;
            $NowView = time();
            $CrntDate = date('Y-m-d', $NowView);
            $currntDateintimeView = strtotime($CrntDate);

            //get imagepath
            $getnewproductsimagenameview = Mage::getStoreConfig('productribbon/mconnectnewproductarrival/new_products_ribbon');
            $getbestproductsimagename = Mage::getStoreConfig('productribbon/mconnectbestproduct/best_products_ribbon');
            $getsalesproductsimagename = Mage::getStoreConfig('productribbon/mconnectsalesproduct/sales_products_ribbon');
            $getreviewproductsimagename = Mage::getStoreConfig('productribbon/mconnectreviewproduct/review_products_ribbon');

            //get value yes/no for displayed ribbon
            //$getconfigNewproductgeneral = Mage::getStoreConfig('productribbon/mconnectgeneral/display_product_label_on_view');
            $getconfigNewproduct = Mage::getStoreConfig('productribbon/mconnectnewproductarrival/display_on_new_product_label_on_view');
            $getconfigBestproduct = Mage::getStoreConfig('productribbon/mconnectbestproduct/display_on_best_product_label_on_view');
            $getconfigSalesproduct = Mage::getStoreConfig('productribbon/mconnectsalesproduct/display_on_sales_product_label_on_view');
            $getconfigReviewedproduct = Mage::getStoreConfig('productribbon/mconnectreviewproduct/display_on_sales_product_label_on_view');

            //get days from admin
            $adminDayFornewproduct = Mage::getStoreConfig('productribbon/mconnectnewproductarrival/number_for_display_ribbon_new');
            $adminDayForBestproduct = Mage::getStoreConfig('productribbon/mconnectbestproduct/number_for_display_ribbon_best');
            $adminDayForReviewproduct = Mage::getStoreConfig('productribbon/mconnectreviewproduct/number_for_display_ribbon_review');

            //get style from admin for ribbon
            $adminStyleNew = Mage::getStoreConfig('productribbon/mconnectnewproductarrival/style_for_logo_new_Ribbon_view');
            $adminStyleBest = Mage::getStoreConfig('productribbon/mconnectbestproduct/style_for_best_Ribbon_view');
            $adminStyleSales = Mage::getStoreConfig('productribbon/mconnectsalesproduct/style_for_sales_Ribbon_view');
            $adminStyleReview = Mage::getStoreConfig('productribbon/mconnectreviewproduct/style_for_review_Ribbon_view');

            //get enable/disable value from store config
            $getnewproductsRibbon = Mage::getStoreConfig('productribbon/mconnectnewproductarrival/new_products_module_enable_disable');
            $getbestproductsRibbon = Mage::getStoreConfig('productribbon/mconnectbestproduct/best_products_module_enable_disable');
            $getsalesproductsRibbon = Mage::getStoreConfig('productribbon/mconnectsalesproduct/sales_products_module_enable_disable');
            $getreviewproductsRibbon = Mage::getStoreConfig('productribbon/mconnectreviewproduct/review_products_module_enable_disable');

            //set position of ribbon
            $getpositionforNewproduct = Mage::getStoreConfig('productribbon/mconnectnewproductarrival/position_new_product');
            $getpositionforBestproduct = Mage::getStoreConfig('productribbon/mconnectbestproduct/position_best_product');
            $getpositionforSalesproduct = Mage::getStoreConfig('productribbon/mconnectsalesproduct/position_sales_product');
            $getpositionforMostRiviewedproduct = Mage::getStoreConfig('productribbon/mconnectreviewproduct/position_reviewed_product');
                    ?>

<?php 
} ?>


<?php if ($_product->getImage() != 'no_selection' && $_product->getImage()){ ?>
<!-- Place somewhere in the <body> of your page -->
<div id="slider" class="flexslider">
  <ul class="slides">
    <?php foreach ($this->getGalleryImages() as $_image){ ?>
        <li>
    <?php if(Mage::getStoreConfig('productribbon/mconnectgeneral/module_enable_disable')){

             //get model for new product    
                if($getnewproductsRibbon == 1 &&  $getconfigNewproduct ==1){
                $NweProductClass = new Mconnect_Productribbon_Block_Productribbon();
                $NweProductClass->MediaNewProduct($adminDayFornewproduct,$productViewSku,$currntDateintimeView,$getnewproductsimagenameview,$adminStyleNew,$getpositionforNewproduct);

               }

               //get model for best seller
                if($getbestproductsRibbon == 1 && $getconfigBestproduct == 1){
                    $BestProductClass = new Mconnect_Productribbon_Block_Productribbon();
                    $BestProductClass->MediaBestProduct($productViewSku,$adminDayForBestproduct,$currntDateintimeView,$getbestproductsimagename,$adminStyleBest,$getpositionforBestproduct);

                 }

               // special price products
                    $specialSpricelabel = $_product->getSpecialPrice();
                    if($getsalesproductsRibbon == 1 && $getconfigSalesproduct == 1){
                        $SalesProductClass = new Mconnect_Productribbon_Block_Productribbon();
                        $SalesProductClass->MediaSalesProduct($specialSpricelabel,$getsalesproductsimagename,$adminStyleSales,$getpositionforSalesproduct);

                    }

              //review products
                if($getreviewproductsRibbon == 1 && $getconfigReviewedproduct == 1){
                    $ReviewProductClass = new Mconnect_Productribbon_Block_Productribbon();
                    $ReviewProductClass->MediaReviewProduct($productViewSku,$adminDayForReviewproduct,$currntDateintimeView,$getreviewproductsimagename,$adminStyleReview,$getpositionforMostRiviewedproduct);

                 }

        } ?>
            <img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" />
        </li>
    <?php } ?>
  </ul>
</div>
<?php if (count($this->getGalleryImages()) > 1) { ?>
<div id="carousel" class="flexslider">
  <ul class="slides">
    <?php foreach ($this->getGalleryImages() as $_image){ ?>
        <li>
           <img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(85); ?>" width="56" height="56" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" />
        </li>
    <?php } ?>
    <!-- items mirrored twice, total of 12 -->
  </ul>
</div>
<?php } ?>
<script type="text/javascript">
jQuery(window).load(function() {
  // The slider being synced must be initialized first
  jQuery('#carousel').flexslider({
    animation: "slide",
    controlNav: false,
    animationLoop: false,
    slideshow: false,
    itemWidth: 85,
    itemMargin: 15,
    asNavFor: '#slider',
    mousewheel: true,
  });

  jQuery('#slider').flexslider({
    animation: "slide",
    controlNav: false,
    animationLoop: false,
    slideshow: false,
    sync: "#carousel",
    lightbox: true,
  });
});
</script>
<?php } ?>
  • magento defaultly call place holder image when call <?php echo $this->helper('catalog/image')->init($this->getProduct() – Amit Bera Oct 6 '14 at 23:53
  • you need to upload placepholder image from admin>system>confi.>cataglog – Amit Bera Oct 7 '14 at 0:03
3

Using Product Image Placeholders

Magento Go uses temporary images as placeholders until the permanent product images are available. The initial placeholder image is the Magento logo, which you can replace with placeholder images of your own design.

enter image description here

                         Product Image Placeholders

To upload product image placeholders:

  1. From the Admin panel, select System > Configuration..
  2. In the Configuration panel on the left, under Catalog, select Catalog.
  3. Click to expand the Product Image Placeholders section.
  4. For each image type, click the Browse button to upload the placeholder image you want to use for the base image, small image, and thumbnail images. If you like, you can use the same image for each type.
  5. When complete, click the Save Config button.

enter image description here

System > Configuration > Catalog: Product Image Placeholders

9

Hi you can get place holder from Mage::getStoreConfig() function

Base image: Mage::getStoreConfig("catalog/placeholder/image_placeholder");

small: Mage::getStoreConfig("catalog/placeholder/small_image_placeholder");

Thumbnail Mage::getStoreConfig("catalog/placeholder/thumbnail_placeholder");

You need just add catalog image path on this url before

  Mage::getSingleton('catalog/product_media_config')->getBaseMediaUrl(). '/placeholder/' .

example getting small pace holder image try this

Mage::getSingleton('catalog/product_media_config')->getBaseMediaUrl(). '/placeholder/' .Mage::getStoreConfig("catalog/placeholder/small_image_placeholder");
  • 1
    Hey, Thanks for the reply, could you please post an example? – Artur Rain Oct 7 '14 at 7:43
  • Sorry, but I did not understand, will you be able to show an example or not? Thanks – Artur Rain Oct 7 '14 at 8:52
  • @amit-bera, thank you Amit Bera. From your tips I made like this $product = Mage::getModel('catalog/product')->load($row->getEntityId()); if($product->getId()) if(!empty($product->getImage())) { //echo $product->getImage(); $image_url = Mage::getModel('catalog/product_media_config')->getMediaUrl($product->getImage());} if($product->getImage() == "no_selection") { $image_url = Mage::getSingleton('catalog/product_media_config')->getBaseMediaUrl(). '/placeholder/' .Mage::getStoreConfig("catalog/placeholder/thumbnail_placeholder"); } – Andhi Irawan Apr 8 '16 at 7:29

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.