1

I try to setup a XML feed so can add my products to Facebook Product Catalog. After search I found this but it get all product images.

    function getProductData($iProduct) {
      Mage::getmodel( 'catalog/product' );
        $aData['title'] = mb_substr( $oProduct->getName(  ), 0, 299, 'UTF-8' );
        $aData['description'] = strip_tags( $oProduct->getShortDescription(  ) );
        $oProduct->getFinalPrice(  );
        $_finalPrice = ;
        $aData['price'] = preg_replace( '/,/', '.', Mage::helper( 'tax' )->getPrice( $oProduct, $_finalPrice, true ) );
        $aData['link'] = mb_substr( $oProduct->getProductUrl(  ), 0, 299, 'UTF-8' );
        $aData['image_link_large'] = mb_substr( Mage::getbaseurl( URL_TYPE_MEDIA ) . 'catalog/product' . $oProduct->getImage(  ), 0, 399, 'UTF-8' );

What I want is to get only the images that the filename contain "facebook".
Something like this "image01facebook.jpg" or "image01_facebook.jpg"

1
  • After a little search I realize that getImage refer to Base Image of product. Then I found this: $_product->getMediaGalleryImages()->getItemByColumnValue('label', 'LABEL_NAME')->getUrl(); and I wonder if $aData['image_link_large'] =$_product->getMediaGalleryImages()->getItemByColumnValue('label', 'LABEL_NAME')->getUrl(); do the job simply adding facebook to label name
    – panosdotk
    Commented Jan 9, 2016 at 19:53

1 Answer 1

2

As you want to tried with media label then it can be good idea.

But for getting media image then you need to load full product object by product id( i.e Mage::getModel('catalog/product')->load($ProductId)) and that is not good idea because it take lot of time to execute and lot of memory to.If you want to this then use any faster way to media image like Faster way to load media images in a product collection.

If you have max 1 image for facebook receptively each product then i will suggest to you create a new image attribute from manage attribute and enable this attribute setting used in product listing =yes.

2
  • My site image format is 1:1. The optimum size for images for Facebook Product Catalog is 1200x630px. I want to upload each image to product so I can export the XML file with this image. Can you tell me please how to modify $aData['image_link_large']
    – panosdotk
    Commented Jan 10, 2016 at 16:02
  • I try your suggestion. I have added a image attribute. How can I get this image to XML?
    – panosdotk
    Commented Jan 22, 2016 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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