Reputation: 1791
I'm have I hope a very simple question about Zend_Feed, but for some reason I can't work out how to use Zend_Feed_Atom.
I'm trying to consume google shopping atom feed, which looks like the following:
<?xml version="1.0" encoding="UTF-8"?>
<feed gd:kind="shopping#products" gd:etag=""DGasYngxPSnbk2d57I7XFo1iC6s/xunARm6Ubdaw8jBCuFbVG_I6sSE"" xmlns="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:s="http://www.google.com/shopping/api/schemas/2010">
<id>tag:google.com,2010:shopping/products</id>
<updated>2012-02-05T15:35:48.784Z</updated>
<title>Shopping Products</title>
<generator version="v1" uri="https://www.googleapis.com/shopping/search/">Search API for Shopping</generator>
<link rel="alternate" type="text/html" href="https://www.googleapis.com/shopping/search/"/>
<link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="https://www.googleapis.com/shopping/search/v1/public/products?alt=atom"/>
<link rel="self" type="application/atom+xml" href="https://www.googleapis.com/shopping/search/v1/public/products?country=GB&q=digital+camera&alt=atom&startIndex=1&maxResults=25"/>
<link rel="next" type="application/atom+xml" href="https://www.googleapis.com/shopping/search/v1/public/products?country=GB&q=digital+camera&alt=atom&startIndex=26&maxResults=25"/>
<link rel="previous" type="application/atom+xml"/>
<openSearch:totalResults>2035890</openSearch:totalResults>
<openSearch:startIndex>1</openSearch:startIndex>
<openSearch:itemsPerPage>25</openSearch:itemsPerPage>
<entry gd:kind="shopping#product">
<id>tag:google.com,2010:shopping/products/5735617/15353500247539618129</id>
<author>
<name>Amazon.co.uk</name>
</author>
<published>2011-04-16T07:12:22.000Z</published>
<updated>2012-02-05T02:40:54.000Z</updated>
<title>Fujifilm FinePix S4000 Digital Camera - (14MP, 30x Optical Zoom) 3-inch LCD</title>
<content type="text">The FinePix S4000 is a new bridge camera from Fujifilm thats truly geared up for a creative challenge. Complete with a 14 megapixel high resolution sensor, a massive 30x Fujinon optical zoom, 3.0 LCD screen and 720p HD video capture (30 fps). Plus, with the flexibility of manual or automatic controls, this camera wont fail to impress. Features such as Scene Recognition Auto, Easy Web Upload, a HDMI port and the added bonus of an Electronic Viewfinder, will all help to enhance your photos. The S4000 is suited to photography enthusiasts who are looking to branch out and improve their photographic skills.</content>
<link rel="alternate" type="text/html" href="http://www.amazon.co.uk/dp/B004G8Q60K/ref=asc_df_B004G8Q60K6433986?smid=A2QB1IPRWM40B4&tag=googlecouk06-21&linkCode=asn&creative=22242&creativeASIN=B004G8Q60K"/>
<link rel="self" type="application/atom+xml" href="https://www.googleapis.com/shopping/search/v1/public/products/5735617/gid/15353500247539618129?alt=atom"/>
<s:product>
<s:googleId>15353500247539618129</s:googleId>
<s:author>
<s:name>Amazon.co.uk</s:name>
<s:accountId>5735617</s:accountId>
</s:author>
<s:creationTime>2011-04-16T07:12:22.000Z</s:creationTime>
<s:modificationTime>2012-02-05T02:40:54.000Z</s:modificationTime>
<s:country>GB</s:country>
<s:language>en</s:language>
<s:title>Fujifilm FinePix S4000 Digital Camera - (14MP, 30x Optical Zoom) 3-inch LCD</s:title>
<s:description>The FinePix S4000 is a new bridge camera from Fujifilm thats truly geared up for a creative challenge. Complete with a 14 megapixel high resolution sensor, a massive 30x Fujinon optical zoom, 3.0 LCD screen and 720p HD video capture (30 fps). Plus, with the flexibility of manual or automatic controls, this camera wont fail to impress. Features such as Scene Recognition Auto, Easy Web Upload, a HDMI port and the added bonus of an Electronic Viewfinder, will all help to enhance your photos. The S4000 is suited to photography enthusiasts who are looking to branch out and improve their photographic skills.</s:description>
<s:link>http://www.amazon.co.uk/dp/B004G8Q60K/ref=asc_df_B004G8Q60K6433986?smid=A2QB1IPRWM40B4&tag=googlecouk06-21&linkCode=asn&creative=22242&creativeASIN=B004G8Q60K</s:link>
<s:brand>Fuji</s:brand>
<s:condition>new</s:condition>
<s:gtin>04547410150742</s:gtin>
<s:gtins>
<s:gtin>04547410150742</s:gtin>
</s:gtins>
<s:inventories>
<s:inventory channel="online" availability="inStock">
<s:price shipping="0.0" currency="GBP">168.0</s:price>
</s:inventory>
</s:inventories>
<s:images>
<s:image link="http://ecx.images-amazon.com/images/I/51qJG-LhpcL.jpg"/>
</s:images>
</s:product>
</entry>
When I use Zend_Feed_Atom I can't get to the namespace s:product which I need to gain access to. So I am trying to extend the Zend_Reader_Entry to gain access to the product element within the atom entry. However I can't get the extension to register.
My Zend_Reader_Entry looks like this:
<?php
class My_Google_Shopping_Product_Entry extends Zend_Feed_Reader_Extension_EntryAbstract{
public function getTitle(){
if(isset($this->_data['title'])){
return $this->_data['title'];
}
$title = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/s:title');
if(!$title){
$title = null;
}
$this->_data['title'] = $title;
return $this->_data['title'];
}
public function getPrice(){
if(isset($this->_data['price'])){
return $this->_data['price'];
}
$price = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/s.price');
if(!$price){
$price = null;
}
$this->_data['price'] = $price;
return $this->_data['price'];
}
public function getDescription(){
if(isset($this->_data['description'])){
return $this->_data['description'];
}
$description = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/s:description');
if(!$description){
$description = null;
}
$this->_data['description'] = $title;
return $this->_data['description'];
}
protected function _registerNamespaces(){
$this->_xpath->registerNamespaces('s', 'http://www.google.com/shopping/api/schemas/2010');
}
}
?>
And I'm trying to load it like this:
if(!Zend_Feed_Reader::isRegistered('Product')){
Zend_Feed_Reader::addPrefixPath('/My/Google/Shopping','My_Google_Shopping');
}
Zend_Feed_Reader::registerExtension('Product');
$feed = Zend_Feed_Reader::import($feedUrl);
Any idea why this won't load and mainly if I am doing this right to pull the data from the atom feed.
Many thanks,
Grant
Upvotes: 1
Views: 291