<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Magento development &#187; Magento code</title>
	<atom:link href="http://www.ecommerceoffice.com/category/magento-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ecommerceoffice.com</link>
	<description>Magento development, programming, modules and widgets directly from professionals</description>
	<lastBuildDate>Wed, 30 May 2012 11:35:25 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Programmatically Unsubscribe Customer</title>
		<link>http://www.ecommerceoffice.com/programmatically-unsubscribe-customer/</link>
		<comments>http://www.ecommerceoffice.com/programmatically-unsubscribe-customer/#comments</comments>
		<pubDate>Sat, 19 May 2012 10:47:22 +0000</pubDate>
		<dc:creator>Ivan Prorskuryakov</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[Magento code]]></category>
		<category><![CDATA[Magento snippets]]></category>

		<guid isPermaLink="false">http://www.ecommerceoffice.com/programmatically-unsubscribe-customer/</guid>
		<description><![CDATA[Use the code given below to unsubscribe the email. Mage::getModel('newsletter/subscriber')-&#62;loadByEmail($emailAddress)-&#62;unsubscribe();]]></description>
				<content:encoded><![CDATA[<p>Use the <a href="http://www.ecommerceoffice.com/tag/code/" class="st_tag internal_tag" rel="tag" title="Posts tagged with code">code</a> given below to unsubscribe the email.</p>
<pre>Mage::getModel('newsletter/subscriber')-&gt;loadByEmail($emailAddress)-&gt;unsubscribe();</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ecommerceoffice.com/programmatically-unsubscribe-customer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Display Magento Store Contact Number</title>
		<link>http://www.ecommerceoffice.com/display-magento-store-contact-number/</link>
		<comments>http://www.ecommerceoffice.com/display-magento-store-contact-number/#comments</comments>
		<pubDate>Sat, 19 May 2012 10:47:22 +0000</pubDate>
		<dc:creator>Ivan Prorskuryakov</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[Magento code]]></category>
		<category><![CDATA[Magento snippets]]></category>

		<guid isPermaLink="false">http://www.ecommerceoffice.com/display-magento-store-contact-number/</guid>
		<description><![CDATA[To display contact number of magento store, we need to just copy and paste the code given below, where we want. Mage::getStoreConfig('general/store_information/phone');]]></description>
				<content:encoded><![CDATA[<p>To display contact number of <a href="http://www.ecommerceoffice.com/tag/magento-2/" class="st_tag internal_tag" rel="tag" title="Posts tagged with magento">magento</a> store, we need to just copy and paste the <a href="http://www.ecommerceoffice.com/tag/code/" class="st_tag internal_tag" rel="tag" title="Posts tagged with code">code</a> given below, where we want.</p>
<pre>Mage::getStoreConfig('general/store_information/phone');</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ecommerceoffice.com/display-magento-store-contact-number/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento adding downloadable product to cart by coding php</title>
		<link>http://www.ecommerceoffice.com/magento-adding-downloadable-product-to-cart-by-coding-php/</link>
		<comments>http://www.ecommerceoffice.com/magento-adding-downloadable-product-to-cart-by-coding-php/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 18:58:17 +0000</pubDate>
		<dc:creator>Ivan Prorskuryakov</dc:creator>
				<category><![CDATA[Magento code]]></category>

		<guid isPermaLink="false">http://www.ecommerceoffice.com/magento-adding-downloadable-product-to-cart-by-coding-php/</guid>
		<description><![CDATA[Probably you know it&#8217;s possible to add a product to the cart via querystring, but may be you prefer code a new module for your needs using Magento objects and methods. So adding a simple product is easy: ... $cart = Mage::getSingleton(&#039;checkout/cart&#039;); // start adding the product try { $cart-&#62;addProduct($product, array(&#039;qty&#039; =&#62; 1)); // save [...]]]></description>
				<content:encoded><![CDATA[<p><!-- ALL ADSENSE ADS DISABLED --></p>
<p>Probably you know it&#8217;s possible to <a href="http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/catalog/adding_a_product_to_the_cart_via_querystring">add a product to the cart via querystring</a>, but may be you prefer <a href="http://www.ecommerceoffice.com/tag/code/" class="st_tag internal_tag" rel="tag" title="Posts tagged with code">code</a> a new module for your needs using <a href="http://www.ecommerceoffice.com/tag/magento-2/" class="st_tag internal_tag" rel="tag" title="Posts tagged with magento">Magento</a> objects and methods.</p>
<p>So adding a simple product is easy:</p>
<pre>

...

$cart = Mage::getSingleton(&#039;checkout/cart&#039;);

// start adding the product

try {

$cart-&gt;addProduct($product, array(&#039;qty&#039; =&gt; 1));

// save the cart

$cart-&gt;save();

$result = null;

} catch (Mage_Core_Exception $e) {

$result = $e-&gt;getMessage();

}
</pre>
<p>But how to add a <a href="http://www.ecommerceoffice.com/tag/downloadable/" class="st_tag internal_tag" rel="tag" title="Posts tagged with downloadable">Downloadable</a> product with its right link? Just try this, it&#8217;s a controller I used to integrate an &#8220;add to cart&#8221; API:</p>
<pre>

public function cartaddAction()
{
$productId  = (int) $this-&gt;getRequest()-&gt;getParam(&#039;id&#039;);
$callback  = (string) $this-&gt;getRequest()-&gt;getParam(&#039;callback&#039;);

$cart = Mage::getSingleton(&#039;checkout/cart&#039;);

// call the Magento catalog/product model
$product = Mage::getModel(&#039;catalog/product&#039;)
// set the current store ID
-&gt;setStoreId(Mage::app()-&gt;getStore()-&gt;getId())
// load the product object
-&gt;load($productId);

$<a href="http://www.ecommerceoffice.com/tag/links/" class="st_tag internal_tag" rel="tag" title="Posts tagged with links">links</a> = Mage::getModel(&#039;downloadable/product_type&#039;)-&gt;getLinks( $product );

foreach ( $<a href="http://www.ecommerceoffice.com/tag/links/" class="st_tag internal_tag" rel="tag" title="Posts tagged with links">links</a> as $link )
if ( preg_match(&quot;/epub/i&quot;, $link-&gt;getTitle()) )
$linkId = $link-&gt;getLinkId();

// Here is the trick to add the right link id

$input = array( &#039;qty&#039; =&gt; 1, &#039;<a href="http://www.ecommerceoffice.com/tag/links/" class="st_tag internal_tag" rel="tag" title="Posts tagged with links">links</a>&#039; =&gt; array( $linkId ) );
$request = new Varien_Object();
$request-&gt;setData($input);

// start adding the product
try {
$cart-&gt;addProduct($product, $request);
// save the cart
$cart-&gt;save();

$result = null;
} catch (Mage_Core_Exception $e) {
$result = $e-&gt;getMessage();
}

// very straightforward, set the cart as updated
Mage::getSingleton(&#039;checkout/session&#039;)-&gt;setCartWasUpdated(true);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ecommerceoffice.com/magento-adding-downloadable-product-to-cart-by-coding-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Magento add Bestseller products by date range</title>
		<link>http://www.ecommerceoffice.com/magento-add-bestseller-products-by-date-range/</link>
		<comments>http://www.ecommerceoffice.com/magento-add-bestseller-products-by-date-range/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 18:58:17 +0000</pubDate>
		<dc:creator>Ivan Prorskuryakov</dc:creator>
				<category><![CDATA[Magento code]]></category>

		<guid isPermaLink="false">http://www.ecommerceoffice.com/magento-add-bestseller-products-by-date-range/</guid>
		<description><![CDATA[Here is how to get a collection of products best sold in a given date range (could be daily, monthly, weekly, etc&#8230;) &#60;ul&#62; &#60;?php $from = date(&#34;Y-m-d H:i:s&#34;, (time()-2592000)); $to = date(&#34;Y-m-d H:i:s&#34;, time()); $_productCollection = Mage::getResourceModel(&#039;reports/product_collection&#039;) -&#62;addAttributeToSelect(&#039;*&#039;) -&#62;addOrderedQty($from, $to, true) -&#62;addAttributeToFilter(&#039;status&#039;, 1) -&#62;setOrder(&#039;ordered_qty&#039;, &#039;desc&#039;) -&#62;getSelect()-&#62;limit(10)-&#62;query(); foreach ( $_productCollection as $prod ) : $_product = [...]]]></description>
				<content:encoded><![CDATA[<p><!-- ALL ADSENSE ADS DISABLED --></p>
<p>Here is how to get a collection of products best sold in a given date range (could be daily, monthly, weekly, etc&#8230;)</p>
<pre>&lt;ul&gt;
&lt;?<a href="http://www.ecommerceoffice.com/tag/php/" class="st_tag internal_tag" rel="tag" title="Posts tagged with php">php</a>
$from = date(&quot;Y-m-d H:i:s&quot;, (time()-2592000));
$to = date(&quot;Y-m-d H:i:s&quot;, time());

$_productCollection = Mage::getResourceModel(&#039;reports/product_collection&#039;)
-&gt;addAttributeToSelect(&#039;*&#039;)
-&gt;addOrderedQty($from, $to, true)
-&gt;addAttributeToFilter(&#039;status&#039;, 1)
-&gt;setOrder(&#039;ordered_qty&#039;, &#039;desc&#039;)
-&gt;getSelect()-&gt;limit(10)-&gt;query();

foreach ( $_productCollection as $prod ) :
$_product = Mage::getModel(&#039;catalog/product&#039;);
$_product-&gt;load($prod[&#039;entity_id&#039;]);
($i%2) ? $even = &quot;class=&#039;even-li&#039;&quot; : $even = &quot;&quot;;
?&gt;
&lt;li &lt;?<a href="http://www.ecommerceoffice.com/tag/php/" class="st_tag internal_tag" rel="tag" title="Posts tagged with php">php</a> echo $even ?&gt;&gt;
&lt;div&gt;&lt;a href=&quot;&lt;?<a href="http://www.ecommerceoffice.com/tag/php/" class="st_tag internal_tag" rel="tag" title="Posts tagged with php">php</a> echo $this-&gt;getUrl($_product-&gt;getUrlPath()) ?&gt;&quot; title=&quot;View &lt;?<a href="http://www.ecommerceoffice.com/tag/php/" class="st_tag internal_tag" rel="tag" title="Posts tagged with php">php</a> echo $_product-&gt;name ?&gt;&quot;&gt;&lt;img src=&quot;&lt;?<a href="http://www.ecommerceoffice.com/tag/php/" class="st_tag internal_tag" rel="tag" title="Posts tagged with php">php</a> echo $this-&gt;helper(&#039;catalog/image&#039;)-&gt;init($_product, &#039;image&#039;)-&gt;resize(48); ?&gt;&quot; alt=&quot;&lt;?<a href="http://www.ecommerceoffice.com/tag/php/" class="st_tag internal_tag" rel="tag" title="Posts tagged with php">php</a> echo $_product-&gt;name ?&gt;&quot;  /&gt;&lt;/a&gt;
&lt;a href=&quot;&lt;?<a href="http://www.ecommerceoffice.com/tag/php/" class="st_tag internal_tag" rel="tag" title="Posts tagged with php">php</a> echo $this-&gt;getUrl($_product-&gt;getUrlPath()) ?&gt;&quot; title=&quot;View &lt;?<a href="http://www.ecommerceoffice.com/tag/php/" class="st_tag internal_tag" rel="tag" title="Posts tagged with php">php</a> echo $_product-&gt;name ?&gt;&quot;&gt;&lt;?<a href="http://www.ecommerceoffice.com/tag/php/" class="st_tag internal_tag" rel="tag" title="Posts tagged with php">php</a> echo Mage::helper(&#039;core/string&#039;)-&gt;truncate($_product-&gt;name, 50) ?&gt;&lt;/a&gt;
&lt;p&gt;&lt;?<a href="http://www.ecommerceoffice.com/tag/php/" class="st_tag internal_tag" rel="tag" title="Posts tagged with php">php</a> echo Mage::helper(&#039;core/string&#039;)-&gt;truncate(strip_tags($_product-&gt;description), 130); ?&gt;&lt;/p&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;?<a href="http://www.ecommerceoffice.com/tag/php/" class="st_tag internal_tag" rel="tag" title="Posts tagged with php">php</a>
endforeach;
?&gt;
&lt;/ul&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ecommerceoffice.com/magento-add-bestseller-products-by-date-range/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento problem with Paypal Express and new customer registration [Solved]</title>
		<link>http://www.ecommerceoffice.com/magento-problem-with-paypal-express-and-new-customer-registration-solved/</link>
		<comments>http://www.ecommerceoffice.com/magento-problem-with-paypal-express-and-new-customer-registration-solved/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 18:58:17 +0000</pubDate>
		<dc:creator>Ivan Prorskuryakov</dc:creator>
				<category><![CDATA[Magento code]]></category>

		<guid isPermaLink="false">http://www.ecommerceoffice.com/magento-problem-with-paypal-express-and-new-customer-registration-solved/</guid>
		<description><![CDATA[You know there is this problem with Magento 1.4.* and 1.5.*, if you are using Paypal Express as payment method and your customer is a new one, when she/he complete the order this is without account association (Customer Group 0 USER NOT LOGGED IN) and the new customer is not created. To solve this problem [...]]]></description>
				<content:encoded><![CDATA[<p><!-- ALL ADSENSE ADS DISABLED --></p>
<p>You know there is this problem with <strong><a href="http://www.ecommerceoffice.com/tag/magento-2/" class="st_tag internal_tag" rel="tag" title="Posts tagged with magento">Magento</a></strong> 1.4.* and 1.5.*, if you are using <strong>Paypal Express</strong> as payment method and your customer is a new one, when she/he complete the order this is without account association (Customer Group 0 <strong>USER NOT LOGGED IN</strong>) and the new customer is not created.</p>
<p>To solve this problem you have to install this useful extension: <a href="https://github.com/onestepcheckout/PaypalRegister">https://github.com/onestepcheckout/PaypalRegister</a></p>
<p>Follow the README and finally you can get registered users with Paypal Express too.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ecommerceoffice.com/magento-problem-with-paypal-express-and-new-customer-registration-solved/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento adding you own custom RSS Feeds</title>
		<link>http://www.ecommerceoffice.com/magento-adding-you-own-custom-rss-feeds/</link>
		<comments>http://www.ecommerceoffice.com/magento-adding-you-own-custom-rss-feeds/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 18:58:17 +0000</pubDate>
		<dc:creator>Ivan Prorskuryakov</dc:creator>
				<category><![CDATA[Magento code]]></category>

		<guid isPermaLink="false">http://www.ecommerceoffice.com/magento-adding-you-own-custom-rss-feeds/</guid>
		<description><![CDATA[You know you will need, before or after, to add your own custom RSS feeds to your Magento. For example, I needed to create some custom RSS Feeds to list bestseller products by date (bestseller weekly, monthly, etc&#8230;) How to do it? It&#8217;s quite complex but not so much if you follow this mini tutorial: [...]]]></description>
				<content:encoded><![CDATA[<p><!-- ALL ADSENSE ADS DISABLED --></p>
<p>You know you will need, before or after, to add your own custom RSS feeds to your <a href="http://www.ecommerceoffice.com/tag/magento-2/" class="st_tag internal_tag" rel="tag" title="Posts tagged with magento">Magento</a>.<br />
For example, I needed to create some custom RSS Feeds to list bestseller products by date (bestseller weekly, monthly, etc&#8230;)<br />
How to do it? It&#8217;s quite complex but not so much if you follow this mini tutorial:</p>
<p>First of all, you need to setup a new namespace directory under your &#8220;local&#8221; dir, this will overwrite your current RSS Mage methods but not all.</p>
<p>So, create your directory app/local/Simplicissimus/Rss. (change Simplicissimus with your own Namespace and change it everywhere)</p>
<p>Create inside it the following directories:</p>
<ul>
<li>Block</li>
<li>Block/Catalog</li>
<li>controllers</li>
<li>etc</li>
</ul>
<p>Starting with the configuration XML, you need to create a file etc/config.xml like this:</p>
<pre>&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;config&gt;
&lt;modules&gt;
&lt;Simplicissimus_Rss&gt;
&lt;version&gt;0.1.0&lt;/version&gt;
&lt;/Simplicissimus_Rss&gt;
&lt;/modules&gt;
&lt;global&gt;
&lt;blocks&gt;
&lt;rss&gt;
&lt;rewrite&gt;
&lt;list&gt;Simplicissimus_Rss_Block_List&lt;/list&gt;
&lt;catalog_<a href="http://www.ecommerceoffice.com/tag/category/" class="st_tag internal_tag" rel="tag" title="Posts tagged with category">category</a>&gt;Simplicissimus_Rss_Block_Catalog_<a href="http://www.ecommerceoffice.com/tag/category/" class="st_tag internal_tag" rel="tag" title="Posts tagged with category">Category</a>&lt;/catalog_<a href="http://www.ecommerceoffice.com/tag/category/" class="st_tag internal_tag" rel="tag" title="Posts tagged with category">category</a>&gt;
&lt;catalog_bestseller&gt;Simplicissimus_Rss_Block_Catalog_Bestseller&lt;/catalog_bestseller&gt;
&lt;catalog_bestsellerweekly&gt;Simplicissimus_Rss_Block_Catalog_Bestsellerweekly&lt;/catalog_bestsellerweekly&gt;
&lt;catalog_bestsellermonthly&gt;Simplicissimus_Rss_Block_Catalog_Bestsellermonthly&lt;/catalog_bestsellermonthly&gt;
&lt;catalog_bestsellernarcissus&gt;Simplicissimus_Rss_Block_Catalog_Bestsellernarcissus&lt;/catalog_bestsellernarcissus&gt;
&lt;catalog_worstseller&gt;Simplicissimus_Rss_Block_Catalog_Worstseller&lt;/catalog_worstseller&gt;
&lt;/rewrite&gt;
&lt;/rss&gt;
&lt;/blocks&gt;
&lt;/global&gt;
&lt;frontend&gt;
&lt;routers&gt;
&lt;rss&gt;
&lt;use&gt;standard&lt;/use&gt;
&lt;args&gt;
&lt;modules&gt;
&lt;Simplicissimus_Rss before=&quot;Mage_Rss&quot;&gt;Simplicissimus_Rss&lt;/Simplicissimus_Rss&gt;
&lt;/modules&gt;
&lt;/args&gt;
&lt;/rss&gt;
&lt;/routers&gt;
&lt;/frontend&gt;
&lt;/config&gt;
</pre>
<p>Now let&#8217;s go create the controller for new RSS urls, create a file called controllers/CatalogController.<a href="http://www.ecommerceoffice.com/tag/php/" class="st_tag internal_tag" rel="tag" title="Posts tagged with php">php</a></p>
<pre>&lt;?php
// Controllers are not autoloaded so we will have to do it manually:
require_once &#039;Mage/Rss/controllers/CatalogController.php&#039;;
class Simplicissimus_Rss_CatalogController extends Mage_Rss_CatalogController
{
public function bestsellerAction()
{
$this-&gt;checkFeedEnable(&#039;bestseller&#039;);
$this-&gt;loadLayout(false);
$this-&gt;renderLayout();
}

public function bestsellerweeklyAction()
{
$this-&gt;checkFeedEnable(&#039;bestsellerweekly&#039;);
$this-&gt;loadLayout(false);
$this-&gt;renderLayout();
}

public function bestsellermonthlyAction()
{
$this-&gt;checkFeedEnable(&#039;bestsellermonthly&#039;);
$this-&gt;loadLayout(false);
$this-&gt;renderLayout();
}

public function bestsellernarcissusAction()
{
$this-&gt;checkFeedEnable(&#039;bestsellernarcissus&#039;);
$this-&gt;loadLayout(false);
$this-&gt;renderLayout();
}

public function worstsellerAction()
{
$this-&gt;checkFeedEnable(&#039;worstseller&#039;);
$this-&gt;loadLayout(false);
$this-&gt;renderLayout();
}
}
</pre>
<p>Now we need blocks, first of all create a file Block/List.php:</p>
<pre>&lt;?php
class Simplicissimus_Rss_Block_List extends Mage_Rss_Block_List
{

public function getRssMiscFeeds()
{
$this-&gt;resetRssFeed();
//$this-&gt;NewProductRssFeed();
//$this-&gt;SpecialProductRssFeed();
$this-&gt;SalesRuleProductRssFeed();

// SBF
$this-&gt;BestsellerRssFeed();
$this-&gt;BestsellerWeeklyRssFeed();
$this-&gt;BestsellerMonthlyRssFeed();
$this-&gt;BestsellerNarcissusRssFeed();
$this-&gt;WorstsellerRssFeed();

return $this-&gt;getRssFeeds();
}

public function BestsellerRssFeed()
{
$path = self::XML_PATH_RSS_METHODS.&#039;/catalog/bestseller&#039;;
if((bool)Mage::getStoreConfig($path)){
$this-&gt;addRssFeed($path, $this-&gt;__(&#039;Ebook Bestseller (All time)&#039;));
}
}

public function BestsellerWeeklyRssFeed()
{
$path = self::XML_PATH_RSS_METHODS.&#039;/catalog/bestsellerweekly&#039;;
if((bool)Mage::getStoreConfig($path)){
$this-&gt;addRssFeed($path, $this-&gt;__(&#039;Ebook Bestseller (Ultima settimana)&#039;));
}
}

public function BestsellerMonthlyRssFeed()
{
$path = self::XML_PATH_RSS_METHODS.&#039;/catalog/bestsellermonthly&#039;;
if((bool)Mage::getStoreConfig($path)){
$this-&gt;addRssFeed($path, $this-&gt;__(&#039;Ebook Bestseller (Ultimo mese)&#039;));
}
}

public function BestsellerNarcissusRssFeed()
{
$path = self::XML_PATH_RSS_METHODS.&#039;/catalog/bestsellernarcissus&#039;;
if((bool)Mage::getStoreConfig($path)){
$this-&gt;addRssFeed($path, $this-&gt;__(&#039;Ebook Bestseller (Narcissus Self Published)&#039;));
}
}

public function WorstsellerRssFeed()
{
$path = self::XML_PATH_RSS_METHODS.&#039;/catalog/worstseller&#039;;
if((bool)Mage::getStoreConfig($path)){
$this-&gt;addRssFeed($path, $this-&gt;__(&#039;Ebook meno venduti&#039;));
}
}

}
</pre>
<p>Well done, now we need to create one block file for each new RSS Feed we wanna publish, this file will be the one with the collection inside. Here I put only one of this for example you should need to complete the others or to remove from the other files:</p>
<pre>
&lt;?php
class Simplicissimus_Rss_Block_Catalog_Bestseller extends Mage_Rss_Block_Abstract
{

/**
* Cache tag constant for feed reviews
*
* @var string
*/
const CACHE_TAG = &#039;block_html_rss_catalog_bestseller&#039;;

protected function _construct()
{
$this-&gt;setCacheTags(array(self::CACHE_TAG));
/*
* setting cache to save the rss for 10 minutes
*/
$this-&gt;setCacheKey(&#039;rss_catalog_bestseller&#039;);
$this-&gt;setCacheLifetime(600);
}

protected function _toHtml()
{
$newurl = Mage::getUrl(&#039;rss/catalog/bestseller&#039;);
$title = Mage::helper(&#039;rss&#039;)-&gt;__(&#039;Ebook Bestseller (All time)&#039;);

$rssObj = Mage::getModel(&#039;rss/rss&#039;);
$data = array(&#039;title&#039; =&gt; $title,
&#039;description&#039; =&gt; $title,
&#039;link&#039;        =&gt; $newurl,
&#039;charset&#039;     =&gt; &#039;UTF-8&#039;,
);
$rssObj-&gt;_addHeader($data);

$_productCollection = Mage::getResourceModel(&#039;reports/product_collection&#039;)
-&gt;addAttributeToSelect(&#039;*&#039;)
-&gt;addOrderedQty()
-&gt;addFieldToFilter(&#039;type_id&#039;,  array(&#039;like&#039;=&gt;&#039;<a href="http://www.ecommerceoffice.com/tag/downloadable/" class="st_tag internal_tag" rel="tag" title="Posts tagged with downloadable">downloadable</a>&#039;))
-&gt;addAttributeToFilter(&#039;status&#039;, 1)
-&gt;setOrder(&#039;ordered_qty&#039;, &#039;desc&#039;)
-&gt;setCurPage(1)
-&gt;setPageSize(20);

if ($_productCollection) {
$args = array(&#039;rssObj&#039; =&gt; $rssObj);
foreach ($_productCollection as $_product) {
$args[&#039;product&#039;] = $_product;
$this-&gt;addBestsellerXmlCallback($args);
}
}

return $rssObj-&gt;createRssXml();
}

public function addBestsellerXmlCallback($args)
{
$product = Mage::getModel(&#039;catalog/product&#039;)-&gt;load($args[&#039;product&#039;][&#039;entity_id&#039;]);

Mage::dispatchEvent(&#039;rss_catalog_category_xml_callback&#039;, $args);

if ( $product-&gt;getTypeId() == &quot;<a href="http://www.ecommerceoffice.com/tag/downloadable/" class="st_tag internal_tag" rel="tag" title="Posts tagged with downloadable">downloadable</a>&quot; )
$extendedDescr = &quot;&lt;p&gt;&lt;strong&gt;Autore: &lt;/strong&gt;&quot; . $product-&gt;getStealth_authors() . &quot;&lt;br /&gt;&lt;strong&gt;Editore: &lt;/strong&gt;&quot; . $product-&gt;getStealth_publisher() . &quot;&lt;br /&gt;&lt;strong&gt;Protezione: &lt;/strong&gt;&quot; . $product-&gt;getStealth_drm();
else
$extendedDescr = &quot;&lt;p&gt;&quot; . $product-&gt;getShortDescription() . &quot;&lt;/p&gt;&quot;;

//Mage::log($product-&gt;getData());

$description = &#039;&lt;table&gt;&lt;tr&gt;&#039;
. &#039;&lt;td&gt;&lt;a href=&quot;&#039;.$product-&gt;getProductUrl().&#039;&quot;&gt;&lt;img src=&quot;&#039;
. $this-&gt;helper(&#039;catalog/image&#039;)-&gt;init($product, &#039;thumbnail&#039;)-&gt;resize(75, 75)
. &#039;&quot; border=&quot;0&quot; align=&quot;left&quot; height=&quot;75&quot; width=&quot;75&quot;&gt;&lt;/a&gt;&lt;/td&gt;&#039;
. &#039;&lt;td  style=&quot;text-decoration:none;&quot;&gt;&#039; . $extendedDescr;

$description .= &#039;&lt;p&gt;&#039; . Mage::app()-&gt;getLocale()-&gt;currency(Mage::app()-&gt;getStore()-&gt;
getCurrentCurrencyCode())-&gt;getSymbol() . &quot; &quot; . $this-&gt;helper(&#039;tax&#039;)-&gt;getPrice($product, $product-&gt;getFinalPrice(), true) . &#039;&lt;/p&gt;&#039;;

$description .= &#039;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#039;;
$rssObj = $args[&#039;rssObj&#039;];
$data = array(
&#039;title&#039;         =&gt; $product-&gt;getName(),
&#039;link&#039;          =&gt; $product-&gt;getProductUrl(),
&#039;description&#039;   =&gt; $description,
);

$rssObj-&gt;_addEntry($data);
}
}
</pre>
<p>You are almost done, now to display your new RSS custom feeds on the RSS page on your Magento (http://&lt;magento_root&gt;/rss) you only need to add them to the DB, simply add them to the table &#8220;core_config_data&#8221;:</p>
<ul>
<li>Scope: default</li>
<li>Scope_id: 0</li>
<li>path: rss/catalog/bestseller</li>
<li>value: 1</li>
</ul>
<p>You are done! Hope you find this guide useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ecommerceoffice.com/magento-adding-you-own-custom-rss-feeds/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Magento Export products in custom XML [script]</title>
		<link>http://www.ecommerceoffice.com/magento-export-products-in-custom-xml-script/</link>
		<comments>http://www.ecommerceoffice.com/magento-export-products-in-custom-xml-script/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 18:54:44 +0000</pubDate>
		<dc:creator>Ivan Prorskuryakov</dc:creator>
				<category><![CDATA[Magento code]]></category>
		<category><![CDATA[category]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[downloadable]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[links]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[products code]]></category>

		<guid isPermaLink="false">http://www.ecommerceoffice.com/?p=941</guid>
		<description><![CDATA[If you have to export all or a part of your Magento products you can try this simple script which creates a products collection and writes a simple and custom XML file per product (but you can simply change it to write a single long XML file). Hope you enjoy it! &#60;?php // Magento XML [...]]]></description>
				<content:encoded><![CDATA[<p>If you have to <a href="http://www.ecommerceoffice.com/tag/export/" class="st_tag internal_tag" rel="tag" title="Posts tagged with export">export</a> all or a part of your <a href="http://www.ecommerceoffice.com/tag/magento-2/" class="st_tag internal_tag" rel="tag" title="Posts tagged with magento">Magento</a> products you can try this simple script which creates a products collection and writes a simple and custom XML file per product (but you can simply change it to write a single long XML file).</p>
<p>Hope you enjoy it!</p>
<pre>&lt;?<a href="http://www.ecommerceoffice.com/tag/php/" class="st_tag internal_tag" rel="tag" title="Posts tagged with php">php</a>
// Magento XML products exporter
// Version 0.1
// by Michele Marcucci
// http://www.michelem.org

require_once 'app/Mage.<a href="http://www.ecommerceoffice.com/tag/php/" class="st_tag internal_tag" rel="tag" title="Posts tagged with php">php</a>';
umask( 0 );
Mage::app( "default" );
Mage::app()-&gt;setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$_magentoPath = "CHANGETHISTOYOURMAGENTOPATH ex: /var/virtual/magento"
$_urlPath = "";
$_imagePath = $_urlPath . "media";
$_logFileName = "export_products.log";
$_xmlPath = $_magentoPath . "/var/export";

Mage::log( "Export start", null, $_logFileName );

// Prepare collection
$_productCollection = Mage::getModel('catalog/product')-&gt;getCollection();
$_productCollection-&gt;addAttributeToSelect('*');

/* You can change and uncomment these lines below to filter your products collection */

// Filter by updated_at date, get only daily changes
//$_productCollection-&gt;addFieldToFilter('updated_at', array('from'=&gt;date("Y-m-d", time()-86400)));

// Filter by product type, get only downloadables
//$_productCollection-&gt;addFieldToFilter('type_id',  array('like'=&gt;'<a href="http://www.ecommerceoffice.com/tag/downloadable/" class="st_tag internal_tag" rel="tag" title="Posts tagged with downloadable">downloadable</a>'));

// Filter by sku get only products with sku like "EBOOK-%"
//$_productCollection-&gt;addFieldToFilter('sku',  array('like'=&gt;'EBOOK-%'));

// Limit output to 15 records
//$_productCollection-&gt;getSelect()-&gt;limit(15);

Mage::log( "Products to be exported: " . $_productCollection-&gt;count(), null, $_logFileName );

$i = 1;
foreach ( $_productCollection as $_product ) {

	// Prepare array of variables to grow XML file
    $v['sku'] = $_product-&gt;getSku();
    $v['product_name'] = $_product-&gt;getName();
	$v['type'] = $_product-&gt;getTypeId();
    $v['description'] = $_product-&gt;getDescription();
    $v['short_description'] = $_product-&gt;getShortDescription();
    $v['meta_title'] = $_product-&gt;getMetaTitle();
    $v['meta_description'] = $_product-&gt;getMetaDescription();
    $v['meta_keyword'] = $_product-&gt;getMetaKeyword();
    $v['created_at'] = $_product-&gt;getCreatedAt();
    $v['updated_at'] = $_product-&gt;getUpdatedAt();
    $v['url_path'] = $_urlPath . $_product-&gt;geturlpath();
    $v['image'] = $_imagePath . $_product-&gt;getImage();
    $v['image_label'] = $_product-&gt;getImageLabel();
  	$v['price'] = $_product-&gt;getPrice();
   	$v['special_price'] = $_product-&gt;getSpecialPrice();
    $v['weight'] = $_product-&gt;getWeight();

	// Get the Magento categories for the product
    $categoryIds = $_product-&gt;getCategoryIds();

	foreach($categoryIds as $categoryId) {
    	$<a href="http://www.ecommerceoffice.com/tag/category/" class="st_tag internal_tag" rel="tag" title="Posts tagged with category">category</a> = Mage::getModel('catalog/<a href="http://www.ecommerceoffice.com/tag/category/" class="st_tag internal_tag" rel="tag" title="Posts tagged with category">category</a>')-&gt;load($categoryId);
    	$v['categories'][$_product-&gt;getSku()][] = $<a href="http://www.ecommerceoffice.com/tag/category/" class="st_tag internal_tag" rel="tag" title="Posts tagged with category">category</a>-&gt;getName();
	}

    // If product is downloadable get some informations about <a href="http://www.ecommerceoffice.com/tag/links/" class="st_tag internal_tag" rel="tag" title="Posts tagged with links">links</a> added
    if ( $_product-&gt;getTypeId() == "downloadable" ) {
    	$_<a href="http://www.ecommerceoffice.com/tag/links/" class="st_tag internal_tag" rel="tag" title="Posts tagged with links">links</a> = Mage::getModel('downloadable/product_type')-&gt;getLinks( $_product );
    	foreach ( $_<a href="http://www.ecommerceoffice.com/tag/links/" class="st_tag internal_tag" rel="tag" title="Posts tagged with links">links</a> as $_link )
    		$v['available_formats'][$_product-&gt;getSku()][] = $_link-&gt;getTitle();
    }

	// Prepare XML file to save
	$xmlFile = $_xmlPath . "/" . $_product-&gt;getSku() . ".xml";

	$doc = new DomDocument('1.0', 'UTF-8');
	$doc-&gt;preserveWhiteSpace = false;
	$doc-&gt;formatOutput = true;	

	$root = $doc-&gt;createElement('product');
	$root = $doc-&gt;appendChild($root);

	$occ = $doc-&gt;createElement('root');
	$occ = $root-&gt;appendChild($occ);

	foreach ( $v as $fieldName =&gt; $fieldValue ) {
		$child = $doc-&gt;createElement($fieldName);
    	$child = $occ-&gt;appendChild($child);

		if ( is_array($fieldValue) ) {
			$value = $doc-&gt;createTextNode(implode( "|", $fieldValue[$_product-&gt;getSku()] ));
			$value = $child-&gt;appendChild($value);
		} else {
			$value = $doc-&gt;createTextNode($fieldValue);
			$value = $child-&gt;appendChild($value);
		}

	}

	// Save each product as XML file
	$doc-&gt;save( $xmlFile );

	Mage::log( "File " . $i . ": " . $_product-&gt;getSku(), null, $_logFileName );

	$i++;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ecommerceoffice.com/magento-export-products-in-custom-xml-script/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Display Most Viewed Products In Magneto</title>
		<link>http://www.ecommerceoffice.com/display-most-viewed-products-in-magneto/</link>
		<comments>http://www.ecommerceoffice.com/display-most-viewed-products-in-magneto/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 21:02:35 +0000</pubDate>
		<dc:creator>Ivan Prorskuryakov</dc:creator>
				<category><![CDATA[Magento code]]></category>

		<guid isPermaLink="false">http://www.ecommerceoffice.com/display-most-viewed-products-in-magneto/</guid>
		<description><![CDATA[One of my client wants his visitor to see most viewed item on product detail page &#8220;view.phtml&#8221;, so i found following solution, it will return array of product just use this array to display most view products. &#60;?php $productCount = 5; $storeId = Mage::app()-&#62;getStore()-&#62;getId(); $products = Mage::getResourceModel('reports/product_collection') -&#62;addAttributeToSelect('*') -&#62;setStoreId($storeId) -&#62;addStoreFilter($storeId) -&#62;addViewsCount() -&#62;setPageSize($productCount); Mage::getSingleton('catalog/product_status') -&#62;addVisibleFilterToCollection($products); Mage::getSingleton('catalog/product_visibility') [...]]]></description>
				<content:encoded><![CDATA[<p>One of my client wants his visitor to see most viewed item on product detail page &#8220;view.phtml&#8221;, so i found following solution,<br />
it will return array of product just use this array to display most view products.</p>
<pre>
&lt;?<a href="http://www.ecommerceoffice.com/tag/php/" class="st_tag internal_tag" rel="tag" title="Posts tagged with php">php</a>
	$productCount = 5;

	$storeId    = Mage::app()-&gt;getStore()-&gt;getId();      

	$products = Mage::getResourceModel('reports/product_collection')
	-&gt;addAttributeToSelect('*')
	-&gt;setStoreId($storeId)
	-&gt;addStoreFilter($storeId)
	-&gt;addViewsCount()
	-&gt;setPageSize($productCount);

	Mage::getSingleton('catalog/product_status')
	-&gt;addVisibleFilterToCollection($products);
	Mage::getSingleton('catalog/product_visibility')
	-&gt;addVisibleInCatalogFilterToCollection($products);

	print&quot;&lt;pre&gt;&quot;;
	print_r($products);
?&gt;
</pre>
<p>note:- the above <a href="http://www.ecommerceoffice.com/tag/code/" class="st_tag internal_tag" rel="tag" title="Posts tagged with code">code</a> will only return array of most viewed products, just manupilate array in your design.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ecommerceoffice.com/display-most-viewed-products-in-magneto/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Add New Country In Magento</title>
		<link>http://www.ecommerceoffice.com/how-to-add-new-country-in-magento/</link>
		<comments>http://www.ecommerceoffice.com/how-to-add-new-country-in-magento/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 21:02:35 +0000</pubDate>
		<dc:creator>Ivan Prorskuryakov</dc:creator>
				<category><![CDATA[Magento code]]></category>

		<guid isPermaLink="false">http://www.ecommerceoffice.com/how-to-add-new-country-in-magento/</guid>
		<description><![CDATA[Its very easy to add new country in magento just follow the the steps given below and your are done with it Step1: Open lib/zend/locale/data/en.xml Step2: Locate territories tag in this file Step3: copy one of territory tags for the syntax and paste it within the territories tag Step4: hard part here is to add [...]]]></description>
				<content:encoded><![CDATA[<p>Its very easy to add new country in <a href="http://www.ecommerceoffice.com/tag/magento-2/" class="st_tag internal_tag" rel="tag" title="Posts tagged with magento">magento</a> just follow the the steps given below and your are done with it</p>
<p>   Step1: Open lib/zend/locale/data/en.xml</p>
<p>   Step2: Locate territories tag in this file</p>
<p>   Step3: copy one of territory tags for the syntax and paste it within the territories tag</p>
<p>   Step4: hard part here is to add country <a href="http://www.ecommerceoffice.com/tag/code/" class="st_tag internal_tag" rel="tag" title="Posts tagged with code">code</a> in this file as might not be able to find a unique one, so it&#8217;s upto you.</p>
<p>   Step5: Save this file</p>
<p>   Step6: Open table name directory_country</p>
<p>   Step7: It has predefined syntax follow then same and create a new row and enter the same country code as entered in the en.xml file in 3 columns.</p>
<p>   Step7: Refresh the site&#8217;s cache.</p>
<p>   Step8: Admin > Configuration > General this new country should be selected in list of allowed countries.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ecommerceoffice.com/how-to-add-new-country-in-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Display Store Categories On HomePage In Magento</title>
		<link>http://www.ecommerceoffice.com/display-store-categories-on-homepage-in-magento/</link>
		<comments>http://www.ecommerceoffice.com/display-store-categories-on-homepage-in-magento/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 21:02:35 +0000</pubDate>
		<dc:creator>Ivan Prorskuryakov</dc:creator>
				<category><![CDATA[Magento code]]></category>

		<guid isPermaLink="false">http://www.ecommerceoffice.com/display-store-categories-on-homepage-in-magento/</guid>
		<description><![CDATA[Display All Magento Category On HomePage With Image Sometime we need to display webstore categories with there images on homepage, its very simple to do it just create a page call it hopepage.phtml then go to magento backend and call cms block. Paste the code below to your homepage.phtml file. &#60;div class=&#34;top-home-category&#34;&#62; &#60;?php $limit = [...]]]></description>
				<content:encoded><![CDATA[<p>Display All <a href="http://www.ecommerceoffice.com/tag/magento-2/" class="st_tag internal_tag" rel="tag" title="Posts tagged with magento">Magento</a> <a href="http://www.ecommerceoffice.com/tag/category/" class="st_tag internal_tag" rel="tag" title="Posts tagged with category">Category</a> On HomePage With Image</p>
<p>Sometime we need to display webstore categories with there images on homepage, its very simple to do it<br />
just create a page call it hopepage.phtml then go to magento backend and call cms block.<br />
Paste the <a href="http://www.ecommerceoffice.com/tag/code/" class="st_tag internal_tag" rel="tag" title="Posts tagged with code">code</a> below to your homepage.phtml file. </p>
<pre>
&lt;div class=&quot;top-home-category&quot;&gt;

    &lt;?<a href="http://www.ecommerceoffice.com/tag/php/" class="st_tag internal_tag" rel="tag" title="Posts tagged with php">php</a>
    $limit = 0;
    $_helper    = $this-&gt;helper('catalog/output');
    foreach ($this-&gt;getStoreCategories() as $_category):

        if($_category-&gt;getIsActive()):

            $cur_category = Mage::getModel('catalog/category')-&gt;load($_category-&gt;getId());

            if ($_imgUrl = $cur_category-&gt;getImageUrl()){

                $_imgHtml = '&lt;img src=&quot;'.$_imgUrl.'&quot; alt=&quot;'.$this-&gt;htmlEscape($cur_category-&gt;getName()).'&quot; title=&quot;'.$this-&gt;htmlEscape($cur_category-&gt;getName()).'&quot;  width=&quot;105px&quot; /&gt;';
                $_imgHtml = $_helper-&gt;categoryAttribute($cur_category, $_imgHtml, 'image');
            } ?&gt;
             &lt;div class=&quot;home-category&quot;&gt;
                &lt;div class=&quot;linkimage&quot;&gt;
                    &lt;a href=&quot;&lt;?<a href="http://www.ecommerceoffice.com/tag/php/" class="st_tag internal_tag" rel="tag" title="Posts tagged with php">php</a> echo $this-&gt;getCategoryUrl($cur_category) ?&gt;&quot; style=&quot;border:none&quot;&gt;
                    &lt;?<a href="http://www.ecommerceoffice.com/tag/php/" class="st_tag internal_tag" rel="tag" title="Posts tagged with php">php</a> echo $_imgHtml; ?&gt;
                    &lt;/a&gt;
                &lt;/div&gt;
                &lt;div class=&quot;category-link-container&quot;&gt;
                &lt;a href=&quot;&lt;?<a href="http://www.ecommerceoffice.com/tag/php/" class="st_tag internal_tag" rel="tag" title="Posts tagged with php">php</a> echo $this-&gt;getCategoryUrl($cur_category) ?&gt;&quot;&gt;
                       &lt;?<a href="http://www.ecommerceoffice.com/tag/php/" class="st_tag internal_tag" rel="tag" title="Posts tagged with php">php</a> echo $_helper-&gt;categoryAttribute($cur_category, $cur_category-&gt;getName(), 'name') ?&gt;
                &lt;/a&gt;
                &lt;/div&gt;
            &lt;/div&gt;

       &lt;?<a href="http://www.ecommerceoffice.com/tag/php/" class="st_tag internal_tag" rel="tag" title="Posts tagged with php">php</a>
           $limit+=1;
        endif;

        if ($limit==8):
            break;
        endif;

    endforeach;
?&gt;
&lt;/div&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ecommerceoffice.com/display-store-categories-on-homepage-in-magento/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
