LemonStand Forum: Output image url in XML feed? - LemonStand Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Output image url in XML feed? Can't get the image url to display in my xml feed for shopping.com

#1 User is offline   clsandford 

  • Member
  • Group: Members
  • Posts: 24
  • Joined: 26-May 11
  • LocationMelbourne, Australia

Posted 26 May 2011 - 01:00 AM

Hope someone is able to point me in the right direction.

I'm trying to get a product's image url to display in my XML feed.
I've used the code from the sitemap to create the XML page, and have got it to output most of the other product details (name, price, sku, etc).

None of the image code that is used else where in lemonstand seems to do the job. The feed just throws me errors with everything.

Here is my feed url: http://www.mensgear..../feed-shopping/

This is my XML code so far:
<?
  echo '<?xml version="1.0" encoding="UTF-8"?>';
  
  $page_list = Cms_Page::create()->where('is_published=1')->where('navigation_visible=1')->where('security_mode_id <> "customers"')->find_all(); // only published, visible and accessible for guests
  $category_list = Shop_Category::create()->find_all();
  $product_list = new Shop_Product(null, array('no_column_init' => true, 'no_validation' => true)); // isn't a necessity, but prevents loading some service objects during loading
  $product_list = $product_list->apply_filters()->find_all();
?>

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<Products>
  <? foreach($product_list as $product): ?>
  <Product>
    <Merchant_SKU><?= h($product->sku) ?></Merchant_SKU>
    <Manufacturer><? if ($product->manufacturer): ?><?= h($product->manufacturer->name) ?><? endif ?></Manufacturer>
    <Product_Name><?= $product->name ?></Product_Name>
    <Product_URL><?= site_url($product->page_url('/product')) ?></Product_URL>
    <? if ($product->is_discounted()): ?>
      <Current_Price><?= format_currency($product->get_discounted_price(1)) ?></Current_Price>
    <? else: ?>
      <Current_Price><?= format_currency($product->price()) ?></Current_Price>
<? endif ?>
    <Original_Price><?= format_currency($product->price()) ?></Original_Price>
    <Product_Description><![CDATA[<?= h($product->short_description) ?>]]></Product_Description>
    <Category_Name></Category_Name>
    <Image_URL></Image_URL>
    <Stock_Availability><? if (!$product->is_out_of_stock()): ?>In Stock<? endif ?><? if ($product->is_out_of_stock()): ?>n<? endif ?></Stock_Availability>
    <Shipping_Rate></Shipping_Rate>
    <? $price = $product->price();?>
    <? $format = substr($price, 0, 1);?>
    <? $price = substr($price, 1);?>
  </Product>
  <? endforeach ?>
</Products>
</urlset>


And these are the snippets I've tried without success:

<?= $image_url ?>

<?= $product->images[0]->getThumbnailPath(100, 350, false) ?>

<? $image_url = $product->image_url(0, 130, 130);
  if ($image_url): ?><?= $image_url ?><? endif ?>

<? foreach ($product->images as $image): ?><?= $image->getThumbnailPath(100, 100) ?><? endforeach ?>


I've tried every other mish mash I can think of (sadly I don't know PHP well enough)

Any help would be brilliant. I've been trying for days to get this to work.
0

#2 User is offline   clsandford 

  • Member
  • Group: Members
  • Posts: 24
  • Joined: 26-May 11
  • LocationMelbourne, Australia

Posted 06 July 2011 - 03:10 PM

We ended up hiring a PHP dude to get it working. Thought I'd share the code with y'all.

I haven't figured out the categories yet. (some price comparison sites require them to match their own list of categories which is somewhat annoying).
We developed this for sites like shopping.com, myshopping.com.au, getprice.com.au

<?
  echo '<?xml version="1.0" encoding="UTF-8"?>';
  $product_list = new Shop_Product(null, array('no_column_init' => true, 'no_validation' => true)); // isn't a necessity, but prevents loading some service objects during loading
  $product_list = $product_list->apply_filters()->find_all();
  ?>

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<Products>
  <? foreach($product_list as $product): ?>
  <? $images = $product->images ?>
  <Product>
    <Merchant_SKU><?= h($product->sku) ?></Merchant_SKU>
    <Manufacturer><? if (!empty($product->manufacturer)): ?><?= h($product->manufacturer->name) ?><? endif ?></Manufacturer>
    <Product_Name><?= h($product->name) ?></Product_Name>
    <Product_URL><?= site_url($product->page_url('/product')) ?></Product_URL>
    <? if ($product->is_discounted()): ?>
      <Current_Price><?= format_currency($product->get_discounted_price(1)) ?></Current_Price>
    <Original_Price><?= format_currency($product->price()) ?></Original_Price>
    <? else: ?>
      <Current_Price><?= format_currency($product->price()) ?></Current_Price>
<? endif ?>
    <Product_Description><![CDATA[<?= h($product->short_description) ?>]]></Product_Description>
    <Category_Name></Category_Name>
    <? if (isset($images[0])): ?>
    <Image_URL>http://www.mensgear.com.au/<?php echo $images[0]->getThumbnailPath(100, 100) ?></Image_URL>
    <? endif; ?>
    <Stock_Availability><? if (!$product->is_out_of_stock()): ?>In Stock<? endif ?><? if ($product->is_out_of_stock()): ?>n<? endif ?></Stock_Availability>
    <Shipping_Rate></Shipping_Rate>
  </Product>
  <? endforeach ?>
</Products>
</urlset>​

0

Share this topic:


Page 1 of 1

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users