<?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>My Silly Point of View &#187; programming</title>
	<atom:link href="http://mysillypointofview.richardferaro.com/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://mysillypointofview.richardferaro.com</link>
	<description>it&#039;s my blog anyway</description>
	<lastBuildDate>Sun, 06 Nov 2011 05:36:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to pull the list of customers from Magento to an external site?</title>
		<link>http://mysillypointofview.richardferaro.com/2010/09/07/how-to-pull-the-list-of-customers-from-magento-to-an-external-site/</link>
		<comments>http://mysillypointofview.richardferaro.com/2010/09/07/how-to-pull-the-list-of-customers-from-magento-to-an-external-site/#comments</comments>
		<pubDate>Tue, 07 Sep 2010 09:09:16 +0000</pubDate>
		<dc:creator>Richard Feraro</dc:creator>
				<category><![CDATA[Feeling guru]]></category>
		<category><![CDATA[Techie Daw]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://mysillypointofview.richardferaro.com/?p=565</guid>
		<description><![CDATA[If you&#8217;re thinking of creating a page that will display your customer list from Magento to a different PHP-based application, you can use the script below to do so. First, let&#8217;s create a file called index.php and inside it, create function (I named it getCustomers()) that will extract an array of customer list and their [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re thinking of creating a page that will display your customer list from Magento to a different PHP-based application, you can use the script below to do so.</p>
<p>First, let&#8217;s create a file called <code>index.php</code> and inside it, create function (I named it <strong>getCustomers()</strong>) that will extract an array of customer list and their information. The function should be able to access the <code>Mage.php</code> file of your Magento instance.</p>
<p><span id="more-565"></span>
<pre class="brush: php; title: ; notranslate">&lt;?php
function getCustomers() {
	/* Magento's Mage.php path
	 * Mage Enabler users may skip these lines
	 */
	require_once (&quot;../magento/app/Mage.php&quot;);
	umask(0);
	Mage::app(&quot;default&quot;);
	/* Magento's Mage.php path */

	/* Get customer model, run a query */
	$collection = Mage::getModel('customer/customer')
				  -&gt;getCollection()
				  -&gt;addAttributeToSelect('*');

	$result = array();
	foreach ($collection as $customer) {
		$result[] = $customer-&gt;toArray();
	}

	return $result;
}
?&gt;</pre>
<p>Once you&#8217;re done with the function, add the HTML tags needed to create the a page with a table for the customer information.</p>
<pre class="brush: xml; first-line: 24; title: ; notranslate">&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Customers&lt;/title&gt;
&lt;style&gt;
table {
	border-collapse: collapse;
}
td {
	padding: 5px;
	border: 1px solid #000000;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;table&gt;
&lt;tr&gt;
	&lt;td&gt;ID&lt;/td&gt;
	&lt;td&gt;Lastname&lt;/td&gt;
	&lt;td&gt;Firstname&lt;/td&gt;
	&lt;td&gt;Email&lt;/td&gt;
	&lt;td&gt;Is Active?&lt;/td&gt;
	&lt;td&gt;Date Created&lt;/td&gt;
	&lt;td&gt;Date Updated&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>After line 47, press return/enter key and add the following script to loop through the array result of our <code>getCustomer()</code> function:</p>
<pre class="brush: php; first-line: 48; title: ; notranslate">&lt;?php
$result = getcustomers();
if(count($result) &gt; 0){
	foreach($result as $key =&gt; $value){
		echo &quot;&lt;tr&gt;&quot;;
			echo &quot;&lt;td&gt;&quot;.$value['entity_id'].&quot;&lt;/td&gt;&quot;;
			echo &quot;&lt;td&gt;&quot;.$value['lastname'].&quot;&lt;/td&gt;&quot;;
			echo &quot;&lt;td&gt;&quot;.$value['firstname'].&quot;&lt;/td&gt;&quot;;
			echo &quot;&lt;td&gt;&quot;.$value['email'].&quot;&lt;/td&gt;&quot;;
			echo &quot;&lt;td&gt;&quot;;
			echo $value['is_active'] == 1 ? &quot;Yes&quot; : &quot;No&quot;;
			echo &quot;&lt;/td&gt;&quot;;
			echo &quot;&lt;td&gt;&quot;.$value['created_at'].&quot;&lt;/td&gt;&quot;;
			echo &quot;&lt;td&gt;&quot;.$value['updated_at'].&quot;&lt;/td&gt;&quot;;
		echo &quot;&lt;/tr&gt;&quot;;
	}
}else{
	echo &quot;&lt;tr&gt;&lt;td colspan=\&quot;7\&quot;&gt;No records found&lt;/td&gt;&lt;/tr&gt;&quot;;
}
?&gt;</pre>
<p>There are several available information within the array that you can also use. Here&#8217;s an example of a record result from our function:</p>
<pre class="brush: php; title: ; notranslate">[0] =&gt; Array
	(
		[entity_id] =&gt; 1
		[entity_type_id] =&gt; 1
		[attribute_set_id] =&gt; 0
		[website_id] =&gt; 1
		[email] =&gt; john.doe@example.com
		[group_id] =&gt; 1
		[increment_id] =&gt; 000000001
		[store_id] =&gt; 1
		[created_at] =&gt; 2007-08-30 23:23:13
		[updated_at] =&gt; 2008-08-08 12:28:24
		[is_active] =&gt; 1
		[firstname] =&gt; John
		[lastname] =&gt; Doe
		[password_hash] =&gt; 2049484a4020ed15d0e4238db22977d5:eg
		[prefix] =&gt;
		[middlename] =&gt;
		[suffix] =&gt;
		[taxvat] =&gt;
		[default_billing] =&gt; 274
		[default_shipping] =&gt; 274
	)</pre>
<p>Save the file as <code>index.php</code> and access it through your browser. It should display a table similar to the one below:</p>
<div id="attachment_574" class="wp-caption aligncenter" style="width: 501px"><a href="http://mysillypointofview.richardferaro.com/wp-content/uploads/2010/09/Customers_list.png"><img class="size-full wp-image-574   " title="Customers_list" src="http://mysillypointofview.richardferaro.com/wp-content/uploads/2010/09/Customers_list.png" alt="Sample table of customers from Magento" width="491" height="266" /></a><p class="wp-caption-text">Sample table of customers from Magento</p></div>
<p>Here&#8217;s the <code>index.php</code> for your reference:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php
function getcustomers() {
	/* Magento's Mage.php path
	 * Mage Enabler users may skip these lines
	 */
	require_once (&quot;../magento/app/Mage.php&quot;);
	umask(0);
	Mage::app(&quot;default&quot;);
	/* Magento's Mage.php path */

	/* Get customer model, run a query */
	$collection = Mage::getModel('customer/customer')
				  -&gt;getCollection()
				  -&gt;addAttributeToSelect('*');

	$result = array();
	foreach ($collection as $customer) {
		$result[] = $customer-&gt;toArray();
	}

	return $result;
}
?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Customers&lt;/title&gt;
&lt;style&gt;
table {
	border-collapse: collapse;
}
td {
	padding: 5px;
	border: 1px solid #000000;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;table&gt;
&lt;tr&gt;
	&lt;td&gt;ID&lt;/td&gt;
	&lt;td&gt;Lastname&lt;/td&gt;
	&lt;td&gt;Firstname&lt;/td&gt;
	&lt;td&gt;Email&lt;/td&gt;
	&lt;td&gt;Is Active?&lt;/td&gt;
	&lt;td&gt;Date Created&lt;/td&gt;
	&lt;td&gt;Date Updated&lt;/td&gt;
&lt;/tr&gt;
&lt;?php
$result = getcustomers();
if(count($result) &gt; 0){
	foreach($result as $key =&gt; $value){
		echo &quot;&lt;tr&gt;&quot;;
			echo &quot;&lt;td&gt;&quot;.$value['entity_id'].&quot;&lt;/td&gt;&quot;;
			echo &quot;&lt;td&gt;&quot;.$value['lastname'].&quot;&lt;/td&gt;&quot;;
			echo &quot;&lt;td&gt;&quot;.$value['firstname'].&quot;&lt;/td&gt;&quot;;
			echo &quot;&lt;td&gt;&quot;.$value['email'].&quot;&lt;/td&gt;&quot;;
			echo &quot;&lt;td&gt;&quot;;
			echo $value['is_active'] == 1 ? &quot;Yes&quot; : &quot;No&quot;;
			echo &quot;&lt;/td&gt;&quot;;
			echo &quot;&lt;td&gt;&quot;.$value['created_at'].&quot;&lt;/td&gt;&quot;;
			echo &quot;&lt;td&gt;&quot;.$value['updated_at'].&quot;&lt;/td&gt;&quot;;
		echo &quot;&lt;/tr&gt;&quot;;
	}
}else{
	echo &quot;&lt;tr&gt;&lt;td colspan=\&quot;7\&quot;&gt;No records found&lt;/td&gt;&lt;/tr&gt;&quot;;
}
?&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://mysillypointofview.richardferaro.com/2010/09/07/how-to-pull-the-list-of-customers-from-magento-to-an-external-site/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to add Magento blocks, CSS and Javascript to an external site</title>
		<link>http://mysillypointofview.richardferaro.com/2010/07/03/how-to-add-magento-blocks-css-and-javascript-to-an-external-site/</link>
		<comments>http://mysillypointofview.richardferaro.com/2010/07/03/how-to-add-magento-blocks-css-and-javascript-to-an-external-site/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 16:01:40 +0000</pubDate>
		<dc:creator>Richard Feraro</dc:creator>
				<category><![CDATA[Feeling guru]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://mysillypointofview.richardferaro.com/?p=535</guid>
		<description><![CDATA[You might have a Magento based website running online and wanted to extend parts of it (also known as blocks, which may include some css and js in the code) to an external site which may either be a blog, another CMS or any other PHP based web application. If you have been following my [...]]]></description>
			<content:encoded><![CDATA[<p>You might have a Magento based website running online and wanted to extend parts of it (also known as blocks, which may include some css and js in the code) to an external site which may either be a blog, another CMS or any other PHP based web application. If you have been following my previous posts, you will know that by adding the Mage.php file of your Magento instance to your application, you can actually pull the needed HTML blocks at any time. The only problem is that most of the examples available online asks you to use the <strong>getChildHtml(&#8216;your-block-here&#8217;)</strong> in which most the time frustrates you because of its complexity and limited resources of how you can actually use it.</p>
<p>There are other ways of doing it. Oddly enough, some are pretty simple and straight forward.<br />
<span id="more-535"></span><br />
We will use a single HTML file which will serve as our &#8216;external&#8217; site. The source code of our <strong>index.php</strong> is shown below:</p>
<pre class="brush: xml; title: ; notranslate">&lt;html&gt;
  &lt;head&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
      WebFontConfig = {
        google: { families: [ 'Josefin Sans Std Light', 'Lobster' ] }
      };
      (function() {
        var wf = document.createElement('script');
        wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
            '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
        wf.type = 'text/javascript';
        wf.async = 'true';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(wf, s);
      })();
    &lt;/script&gt;
    &lt;style type=&quot;text/css&quot;&gt;
      .wf-active p.text {
        font-family: 'Calibri', serif;
		font-size: 16px;
		text-align: justify;
		color:#666666;
		border: 1px solid #CCCCCC;
		-moz-border-radius: 20px;
		-webkit-border-radius: 20px;
		padding: 20px
      }

	  .wf-active h2 {
	  	font-family: 'Lobster', serif;
        font-size: 20px;
		color: #666666
      }

      .wf-active h1 {
        font-family: 'Lobster', serif;
        font-size: 45px;
		color: #006699;
		margin-bottom: 10px;
      }

	  div.body {
	  	max-width: 850px;
		margin: auto;
		background-color: #FFFFFF;
		padding: 30px 50px 0px 50px;
		text-align: left;
		height: 60%;
	  }

	  p.bugs {
	  	font: 12px/1.55 Arial,Helvetica,sans-serif;
		text-align: center;
	  }

	  p.otherdata {
	  	font-family: 'Calibri', serif;
		font-size: 15px;
		color: #999999;
		margin-bottom: 20px
	  }

	  .otherdata strong {
	  	color: #000000
	  }
    &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  	&lt;div class=&quot;body&quot;&gt;
		&lt;h1&gt;How to add Magento blocks, CSS and Javascript to an external site&lt;/h1&gt;
		&lt;p class=&quot;otherdata&quot;&gt;Written by &lt;strong&gt;Richard Feraro&lt;/strong&gt; | Posted on &lt;strong&gt;July 2, 2010&lt;/strong&gt;&lt;/p&gt;
		&lt;p class=&quot;text&quot;&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis a quam massa. Nullam eget erat metus. Sed vel justo enim. Proin rhoncus laoreet bibendum. Nullam eget est nisi. In eget sem in erat sodales bibendum. Morbi gravida augue sed felis tincidunt a congue dui placerat. Aliquam purus risus, mollis sed ullamcorper non, viverra eu odio. Suspendisse nibh nisi, suscipit at viverra eu, convallis ac odio. Morbi nec sapien eros. Suspendisse nec nulla erat, ac porttitor neque. Integer felis dolor, sollicitudin sed semper et, imperdiet nec turpis. Proin blandit luctus egestas. &lt;/p&gt;
	&lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre>
<p>The code above shall produce a page like the one in the screenshot below.</p>
<div id="attachment_538" class="wp-caption aligncenter" style="width: 487px"><a href="http://mysillypointofview.richardferaro.com/wp-content/uploads/2010/07/sample_external_site.png"><img class="size-full wp-image-538     " title="Sample External Page" src="http://mysillypointofview.richardferaro.com/wp-content/uploads/2010/07/sample_external_site.png" alt="" width="477" height="239" /></a><p class="wp-caption-text">Our Sample External Page</p></div>
<p>We&#8217;ll start editing at the beginning of the file by adding a <code>require_once()</code> for our <code>Mage.php</code> file.</p>
<pre class="brush: php; title: ; notranslate">// Your Magento Mage.php
// Mage Enabler WordPress plugin users may
// skip these lines
require_once (&quot;/your/magento/app/Mage.php&quot;);
umask(0);
Mage::app(&quot;default&quot;);</pre>
<p>Proceed with adding the <code>if(class_exists('Mage')){...}</code> which encloses our Magento scripts to prevent the site from breaking if in case the Mage object failed to be instantiated. Check the inline comments for more details.</p>
<pre class="brush: php; title: ; notranslate">// Make sure to execute this block of code
// only if Mage object is present
if(class_exists('Mage')){
	// Instantiate session and generate needed cookie
	Mage::getSingleton('core/session', array('name' =&gt; 'frontend'));
	$Block = Mage::getSingleton('core/layout');

	// Start pulling the blocks
	$head = $Block-&gt;createBlock('Page/Html_Head');
	// Add default css
	// Magento adds the default skin directory
	// 'skin/frontend/default/default' before 'css/styles.css'
	// making it look like the URL below:
	// http://localhost/magento/skin/frontend/default/default/css/styles.css
	$head-&gt;addCss('css/styles.css');
	// Add Prototype JS file
	// Note that it automatically adds the 'js' directory at the beginning
	// making it look like the URL below:
	// http://localhost/magento/js/prototype/prototype.js
	$head-&gt;addJs('prototype/prototype.js');

	// Get the header's HTML
	$header = $Block-&gt;createBlock('Page/Html_Header');
	$header-&gt;setTemplate('page/html/header.phtml');

	// And the footer's HTML as well
	$footer = $Block-&gt;createBlock('Page/Html_Footer');
	$footer-&gt;setTemplate('page/html/footer.phtml');
}</pre>
<p>That&#8217;s it. The codes above will generate the Magento session, the 3 blocks for CSS/JS (which uses the default skin of Magento and adds the Prototype JS file) and the HTML tags for the header and footer.</p>
<p>To use the blocks, insert the CSS/JS block right before the end tag of <code>&lt;/HEAD&gt;</code>:</p>
<pre class="brush: php; title: ; notranslate">	&lt;?php
		// Display the needed tags for CSS and JS
		echo (class_exists('Mage')) ? $head-&gt;getCssJsHtml() : '' ;
	?&gt;
&lt;/head&gt;</pre>
<p>Proceed by adding the Magento header block right after the <code>&lt;BODY&gt;</code> tag but before the <code>&lt;DIV&gt;</code> tag.</p>
<pre class="brush: php; title: ; notranslate">&lt;body&gt;
  	&lt;?php
		// Display the Header HTML
		echo (class_exists('Mage')) ? $header-&gt;toHTML() : '' ;
	?&gt;
  	&lt;div class=&quot;body&quot;&gt;</pre>
<p>Finally, add the Magento footer block right between the end tag of <code>&lt;/DIV&gt;</code> and <code>&lt;/BODY&gt;</code> tag</p>
<pre class="brush: php; title: ; notranslate">	&lt;/div&gt;
	&lt;?php
		// Display the Footer HTML
		echo (class_exists('Mage')) ? $footer-&gt;toHTML() : '' ;
	?&gt;
  &lt;/body&gt;</pre>
<p>It should display a page of our external site which now uses the header and footer of Magento. Check the source to see the additional tags generated.</p>
<div id="attachment_544" class="wp-caption aligncenter" style="width: 483px"><a href="http://mysillypointofview.richardferaro.com/wp-content/uploads/2010/07/sample_external_site_with_magento_blocks.png"><img class="size-full wp-image-544    " title="Our Sample External Page with Magento CSS, Prototype JS, Header and Footer" src="http://mysillypointofview.richardferaro.com/wp-content/uploads/2010/07/sample_external_site_with_magento_blocks.png" alt="" width="473" height="273" /></a><p class="wp-caption-text">Our Sample External Page with Magento CSS, Prototype JS, Header and Footer</p></div>
<p>The full <strong>index.php</strong> can be found below:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php
// Your Magento Mage.php
// Mage Enabler WordPress plugin users may
// skip line numbers 5, 6 and 7
require_once (&quot;/your/magento/app/Mage.php&quot;);
umask(0);
Mage::app(&quot;default&quot;);

// Make sure to execute this block of code
// only if Mage object is present
if(class_exists('Mage')){
	// Instantiate session and generate needed cookie
	Mage::getSingleton('core/session', array('name' =&gt; 'frontend'));
	$Block = Mage::getSingleton('core/layout');

	// Start pulling the blocks
	$head = $Block-&gt;createBlock('Page/Html_Head');
	// Add default css
	// Magento adds the default skin directory
	// 'skin/frontend/default/default' before 'css/styles.css'
	// making it look like the URL below:
	// http://localhost/magento/skin/frontend/default/default/css/styles.css
	$head-&gt;addCss('css/styles.css');
	// Add Prototype JS file
	// Note that it automatically adds the 'js' directory at the beginning
	// making it look like the URL below:
	// http://localhost/magento/js/prototype/prototype.js
	$head-&gt;addJs('prototype/prototype.js');

	// Get the header's HTML
	$header = $Block-&gt;createBlock('Page/Html_Header');
	$header-&gt;setTemplate('page/html/header.phtml');

	// And the footer's HTML as well
	$footer = $Block-&gt;createBlock('Page/Html_Footer');
	$footer-&gt;setTemplate('page/html/footer.phtml');
}

?&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
      WebFontConfig = {
        google: { families: [ 'Josefin Sans Std Light', 'Lobster' ] }
      };
      (function() {
        var wf = document.createElement('script');
        wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
            '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
        wf.type = 'text/javascript';
        wf.async = 'true';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(wf, s);
      })();
    &lt;/script&gt;
    &lt;style type=&quot;text/css&quot;&gt;
      .wf-active p.text {
        font-family: 'Calibri', serif;
		font-size: 16px;
		text-align: justify;
		color:#666666;
		border: 1px solid #CCCCCC;
		-moz-border-radius: 20px;
		-webkit-border-radius: 20px;
		padding: 20px
      }

	  .wf-active h2 {
	  	font-family: 'Lobster', serif;
        font-size: 20px;
		color: #666666
      }

      .wf-active h1 {
        font-family: 'Lobster', serif;
        font-size: 45px;
		color: #006699;
		margin-bottom: 10px;
      }

	  div.body {
	  	max-width: 850px;
		margin: auto;
		background-color: #FFFFFF;
		padding: 30px 50px 0px 50px;
		text-align: left;
		height: 60%;
	  }

	  p.bugs {
	  	font: 12px/1.55 Arial,Helvetica,sans-serif;
		text-align: center;
	  }

	  p.otherdata {
	  	font-family: 'Calibri', serif;
		font-size: 15px;
		color: #999999;
		margin-bottom: 20px
	  }

	  .otherdata strong {
	  	color: #000000
	  }
    &lt;/style&gt;
	&lt;?php
		// Display the needed tags for CSS and JS
		echo (class_exists('Mage')) ? $head-&gt;getCssJsHtml() : '' ;
	?&gt;
  &lt;/head&gt;
  &lt;body&gt;
  	&lt;?php
		// Display the Header HTML
		echo (class_exists('Mage')) ? $header-&gt;toHTML() : '' ;
	?&gt;
  	&lt;div class=&quot;body&quot;&gt;
		&lt;h1&gt;How to add Magento blocks, CSS and Javascript to an external site&lt;/h1&gt;
		&lt;p class=&quot;otherdata&quot;&gt;Written by &lt;strong&gt;Richard Feraro&lt;/strong&gt; | Posted on &lt;strong&gt;July 2, 2010&lt;/strong&gt;&lt;/p&gt;
		&lt;p class=&quot;text&quot;&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis a quam massa. Nullam eget erat metus. Sed vel justo enim. Proin rhoncus laoreet bibendum. Nullam eget est nisi. In eget sem in erat sodales bibendum. Morbi gravida augue sed felis tincidunt a congue dui placerat. Aliquam purus risus, mollis sed ullamcorper non, viverra eu odio. Suspendisse nibh nisi, suscipit at viverra eu, convallis ac odio. Morbi nec sapien eros. Suspendisse nec nulla erat, ac porttitor neque. Integer felis dolor, sollicitudin sed semper et, imperdiet nec turpis. Proin blandit luctus egestas. &lt;/p&gt;
	&lt;/div&gt;
	&lt;?php
		// Display the Footer HTML
		echo (class_exists('Mage')) ? $footer-&gt;toHTML() : '' ;
	?&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://mysillypointofview.richardferaro.com/2010/07/03/how-to-add-magento-blocks-css-and-javascript-to-an-external-site/feed/</wfw:commentRss>
		<slash:comments>86</slash:comments>
		</item>
		<item>
		<title>How to add a product with custom options into Magento shopping cart from an external site?</title>
		<link>http://mysillypointofview.richardferaro.com/2010/06/04/add-a-product-with-custom-options-into-magento-cart-from-external-site/</link>
		<comments>http://mysillypointofview.richardferaro.com/2010/06/04/add-a-product-with-custom-options-into-magento-cart-from-external-site/#comments</comments>
		<pubDate>Fri, 04 Jun 2010 09:49:57 +0000</pubDate>
		<dc:creator>Richard Feraro</dc:creator>
				<category><![CDATA[Feeling guru]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://mysillypointofview.richardferaro.com/?p=521</guid>
		<description><![CDATA[This is a follow up post to a previous article I wrote on how to add products into Magento but this time the script includes custom options (attributes) of the product. I used Magento version 1.4.0.1 in this example. Just copy the whole script and save it as index.php.]]></description>
			<content:encoded><![CDATA[<p>This is a follow up post to a previous <a href="http://mysillypointofview.richardferaro.com/2009/04/27/how-to-add-a-product-into-magento-from-an-external-site/">article</a> I wrote on how to add products into Magento but this time the script includes custom options (attributes) of the product. I used Magento version 1.4.0.1 in this example. Just copy the whole script and save it as <strong>index.php</strong>.</p>
<p><span id="more-521"></span>
<pre class="brush: php; title: ; notranslate">&lt;?php
require_once (&quot;/var/www/your-magento-directory/app/Mage.php&quot;);
umask(0);

// Initialize Magento
Mage::app(&quot;default&quot;);

// You have two options here,
// &quot;frontend&quot; for frontend session or &quot;adminhtml&quot; for admin session
Mage::getSingleton(&quot;core/session&quot;, array(&quot;name&quot; =&gt; &quot;frontend&quot;));

// get the current Magento cart
$cart = Mage::getSingleton('checkout/cart');

if(isset($_POST['submit'])){

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

	// start adding the product
	// format: addProduct(&lt;product id&gt;, array(
	//         'qty' =&gt; &lt;quantity&gt;,
	//         'super_attribute' =&gt; array(&lt;attribute id&gt; =&gt; &lt;option id&gt;)
	//     )
	// )
	$cart-&gt;addProduct($product, array(
			'qty' =&gt; $_POST['qty'],
			'super_attribute' =&gt; array( key($_POST['super_attribute']) =&gt; $_POST['super_attribute'][525] )
			)
		);

	// save the cart
	$cart-&gt;save();

	// very straightforward, set the cart as updated
	Mage::getSingleton('checkout/session')-&gt;setCartWasUpdated(true);

	// redirect to index.php
	header(&quot;Location: index.php&quot;);

}else{
?&gt;
&lt;html&gt;
&lt;head&gt;&lt;/head&gt;
&lt;body&gt;
&lt;div style=&quot;width: 400px; margin: auto&quot;&gt;
	&lt;h3&gt;Very Nice T-shirt&lt;/h3&gt;
	&lt;hr&gt;
	&lt;div style=&quot;width: 180px; margin:auto; line-height: 30px&quot;&gt;
		&lt;form action=&quot;index.php&quot; method=&quot;post&quot;&gt;
			Size:
			&lt;select name=&quot;super_attribute[525]&quot;&gt;
				&lt;option value=&quot;&quot;&gt;Choose an option...&lt;/option&gt;
				&lt;option value=&quot;100&quot;&gt;Small&lt;/option&gt;
				&lt;option value=&quot;99&quot;&gt;Medium&lt;/option&gt;
				&lt;option value=&quot;98&quot;&gt;Large&lt;/option&gt;
			&lt;/select&gt;&lt;br&gt;
			Quantity: &lt;input type=&quot;text&quot; name=&quot;qty&quot; size=&quot;1&quot; value=&quot;1&quot;&gt;
			&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Add This&quot;&gt;
			&lt;input type=&quot;hidden&quot; name=&quot;product&quot; value=&quot;119&quot;&gt;
		&lt;/form&gt;
	&lt;/div&gt;
	&lt;hr&gt;
	&lt;strong&gt;&lt;?php echo &quot;Cart Qty: &quot;.$cart-&gt;getItemsQty();?&gt;&lt;/strong&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;?php } ?&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://mysillypointofview.richardferaro.com/2010/06/04/add-a-product-with-custom-options-into-magento-cart-from-external-site/feed/</wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
		<item>
		<title>How to fix the &#8216;The plugin does not have a valid header&#8217; error when activating a WordPress plugin</title>
		<link>http://mysillypointofview.richardferaro.com/2010/05/27/fix-the-plugin-does-not-have-a-valid-header-error/</link>
		<comments>http://mysillypointofview.richardferaro.com/2010/05/27/fix-the-plugin-does-not-have-a-valid-header-error/#comments</comments>
		<pubDate>Wed, 26 May 2010 16:03:27 +0000</pubDate>
		<dc:creator>Richard Feraro</dc:creator>
				<category><![CDATA[Feeling guru]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://mysillypointofview.wordpress.com/?p=420</guid>
		<description><![CDATA[You want to extend WordPress&#8217; functionality and decided to download some plugins found in the Official WordPress Plugin repository. After searching the repo, you&#8217;ve found two plugins that accomplishes the tasks you needed to implement in your blog. Downloading the plugins gives you two ZIP files that when double-clicked, shows you the contents in the [...]]]></description>
			<content:encoded><![CDATA[<p>You want to extend WordPress&#8217; functionality and decided to download some plugins found in the <a href="http://wordpress.org/extend/plugins/">Official WordPress Plugin</a> repository. After searching the repo, you&#8217;ve found two plugins that accomplishes the tasks you needed to implement in your blog. Downloading the plugins gives you two ZIP files that when double-clicked, shows you the contents in the following format:</p>
<blockquote><p><strong>plugin-a.zip</strong></p>
<pre style="white-space: pre">plugin-a-folder
---- plugin-a-main-file.php
---- plugin-a-readme.txt</pre>
</blockquote>
<p></p>
<blockquote><p>
<strong>plugin-b.zip</strong></p>
<pre style="white-space: pre">plugin-b-folder
---- plugin-b-subfolder
-------- plugin-b-main-file.php
-------- plugin-b-readme.txt</pre>
</blockquote>
<p></p>
<p><span id="more-420"></span>There are two ways to install a plugin. <strong>Option 1</strong> is to unzip the file and upload the contents to <code>wordpress_root/wp-content/plugins/</code> directory. <strong>Option 2</strong> is to use the <code>Add New -&gt; Upload</code> option found in the left panel bar of the administrative page of WordPress. Let&#8217;s assume the two plugins went through the two installation options.</p>
<h4>Installing &#8216;plugin-a.zip&#8217; using Option 1</h4>
<ol>
<li>Unzip the file</li>
<li>Upload the contents to <code>wordpress_root/wp-content/plugins/</code></li>
<li>Login as admin and go to <code>Plugins -&gt; Installed</code>.</li>
<li>Locate plugin and click <span style="text-decoration:underline;">Activate</span> link.</li>
<li><strong>Result:</strong>
<div style="display:inline;border:1px solid #E6DB55;background:#FFFFE0;-moz-border-radius:3px 3px 3px 3px;padding:3px 10px;">Plugin <strong>activated.</strong></div>
</li>
</ol>
<h4>Installing &#8216;plugin-a.zip&#8217; using Option 2</h4>
<ol>
<li>Login as admin and go to <code>Plugins -&gt; Add New -&gt; Upload</code></li>
<li>Locate the file <code>plugin-a.zip</code> by clicking the <em>Browse</em> button.</li>
<li>Click <em>Install Now</em> button.</li>
<li><strong>Result:</strong><br />
	Unpacking the package?<br />
Installing the plugin?<br />
Plugin installed successfully.
	</li>
<li>Click <span style="text-decoration:underline;">Activate Plugin</span> link.</li>
<li><strong>Result:</strong>
<div style="display:inline;border:1px solid #E6DB55;background:#FFFFE0;-moz-border-radius:3px 3px 3px 3px;padding:3px 10px;">Plugin <strong>activated.</strong></div>
</ol>
<h4>Installing &#8216;plugin-b.zip&#8217; using Option 1</h4>
<ol>
<li>Unzip the file</li>
<li>Upload the contents to <code>wordpress_root/wp-content/plugins/</code></li>
<li>Login as admin and go to <code>Plugins -&gt; Installed</code>.</li>
<li>Locate plugin and click <span style="text-decoration:underline;">Activate</span> link.</li>
<li><span style="color:#FF0000;"><strong>Error:</strong> Plugin does not exists in the list.</span></li>
</ol>
<h4>Installing &#8216;plugin-b.zip&#8217; using Option 2</h4>
<ol>
<li>Login as admin and go to <code>Plugins -&gt; Add New -&gt; Upload</code></li>
<li>Locate the file <code>plugin-b.zip</code> by clicking the <em>Browse</em> button.</li>
<li>Click <em>Install Now</em> button.</li>
<li><strong>Result:</strong><br />
	Unpacking the package?<br />
Installing the plugin?<br />
Plugin installed successfully.
	</li>
<li>Click <span style="text-decoration:underline;">Activate Plugin</span> link.</li>
<li><span style="color:#FF0000;"><strong>WordPress ? Error</strong></span>
<div style="color:#333333;display:block;border:1px solid #DFDFDF;background:#FFFFFF;-moz-border-radius:11px 11px 11px 11px;font-family:'Lucida Grande',Verdana,Arial,'Bitstream Vera Sans',sans-serif;padding:1em 2em;">The plugin does not have a valid header.</div>
</ol>
<p>Based on our testing, <code>plugin-b.zip</code> seems to fail on both methods of installation. To find out what is causing the error, we have to understand how the plugin installation works. Upon checking the core files I found this excerpt in <strong>get_plugins()</strong> function:</p>
<blockquote><p>* WordPress only supports plugin files in the base plugins directory<br />
 * (wp-content/plugins) and in one directory above the plugins directory<br />
 * (wp-content/plugins/my-plugin). The file it looks for has the plugin data and<br />
 * must be found in those two locations. It is recommended that do keep your<br />
 * plugin files in directories.</p></blockquote>
<p>The plugin data that the function is looking for can be found below:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php
/*
Plugin Name: Name Of The Plugin
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: A brief description of the Plugin.
Version: The Plugin's Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
Author URI: http://URI_Of_The_Plugin_Author
License: A &quot;Slug&quot; license name e.g. GPL2
*/
?&gt;</pre>
<p>So in order to properly install and activate a plugin, the following two conditions must be satisfied:</p>
<ul>
<li>that a plugin main file (.php) must be placed in <code>plugins</code> root folder or in <strong>first-level subdirectory within plugins folder</strong></li>
<li>and it should contain the necessary plugin data for identification/validation purposes</li>
</ul>
<p>In the case of <code>plugin-b.zip</code>, although the main PHP file contains the needed plugin data, the <strong>validate_plugin()</strong> function returned an error since neither the file can be found or check if it contains the plugin data because it is placed in the <strong>second level subdirectory</strong>, <span style="text-decoration:underline;">a directory location in which the function is not designed to scan the content.</span></p>
<p>To fix the <code>plugin-b.zip</code> file, it needs to have the following content structure:</p>
<blockquote><p><strong>plugin-b.zip</strong></p>
<pre style="white-space: pre">plugin-b-folder
---- plugin-b-main-file.php
---- plugin-b-readme.txt</pre>
</blockquote>
<p></p>
<p>I hope this post will enlighten WordPress users who wants to maximize their blog&#8217;s potential <img src='http://mysillypointofview.richardferaro.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://mysillypointofview.richardferaro.com/2010/05/27/fix-the-plugin-does-not-have-a-valid-header-error/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>Mage Enabler: A plugin to run Magento&#039;s session within WordPress</title>
		<link>http://mysillypointofview.richardferaro.com/2010/05/11/mage-enabler/</link>
		<comments>http://mysillypointofview.richardferaro.com/2010/05/11/mage-enabler/#comments</comments>
		<pubDate>Tue, 11 May 2010 10:56:30 +0000</pubDate>
		<dc:creator>Richard Feraro</dc:creator>
				<category><![CDATA[Feeling guru]]></category>
		<category><![CDATA[Techie Daw]]></category>
		<category><![CDATA[e-commerce]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://mysillypointofview.wordpress.com/?p=350</guid>
		<description><![CDATA[Update (May 12, 2010): Mage Enabler is now available in the Official WordPress Plugin repository. Get it here! It&#8217;s been a while since I posted my tweak that allows Mage object to be utilized within any WordPress installation. The tweak requires the blog owner to modify functions.php as stated in my post. I&#8217;m inspired by [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-365" title="mage_enabler" src="http://mysillypointofview.files.wordpress.com/2010/05/mage_enabler.png" alt="Mage Enabler" width="497" height="167" /></p>
<p><strong>Update (May 12, 2010):</strong> Mage Enabler is now available in the Official WordPress Plugin repository. <a href="http://wordpress.org/extend/plugins/mage-enabler/">Get it here!</a></p>
<p>It&#8217;s been a while since I posted my tweak that allows Mage object to be utilized within any WordPress installation. The tweak requires the blog owner to modify <strong>functions.php</strong> as stated in my <a href="http://mysillypointofview.wordpress.com/2010/04/08/how-to-use-magentos-session-within-wordpress/">post</a>. I&#8217;m inspired by the feedback of the readers who used the tweak so I decided that a plugin that does the same thing should be made to prevent modifying the WordPress core files thus preventing the tweak to cause inconsistencies when an upgrade is necessary.</p>
<p><span id="more-350"></span>It is my pleasure to introduce to you, <strong>Mage Enabler</strong> plugin. <del datetime="2010-05-12T06:31:45+00:00">Just copy the whole code snippet below and save it as <em>mage-enabler.php</em>. Place it inside a folder named <strong>mage-enabler</strong> together with the <em>readme.txt</em> available right after the code block.</del> Please take time to read and follow the readme.txt instruction on how to install the plugin in your WordPress setup.</p>
<h2>How to use the plugin?</h2>
<p>To show you how the plugin works, I&#8217;ve decided to convert my example in my previous <a href="http://mysillypointofview.wordpress.com/2010/04/08/how-to-use-magentos-session-within-wordpress/">post</a> by providing a single login page for both WordPress (subscriber) and Magento (customer). This setup assumes that the account credentials (subcriber/customer) in both database are the same and that the function collision problem between WordPress and Magento has been <a href="http://mysillypointofview.wordpress.com/2010/04/08/how-to-use-magentos-session-within-wordpress/">fixed</a>. If you followed the <strong>functions.php</strong> update in that post, <strong>remove the block of code added at line 4123 to 4138</strong>.</p>
<p>Location of functions.php</p>
<pre>path-to-your-root-htdocs/wordpress/wp-includes/functions.php</pre>
<p>Let&#8217;s start by opening the <strong>index.php</strong> file of the WordPress theme Twenty Ten. I&#8217;m using version 3.0-beta1 of WordPress in this article. You can replicate the same code update to any WordPress version and theme you have.</p>
<pre>wordpress_root\wp-content\themes\twentyten\index.php</pre>
<p>Copy the necessary codes (lines 16-18 and 22-40) to make it similar below:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php

/**
 * The main template file
 *
 * This is the most generic template file in a WordPress theme
 * and one of the two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * E.g., it puts together the home page when no home.php file exists.
 * Learn more: http://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage Twenty Ten
 * @since 3.0.0
 */
 if(class_exists('Mage')){
 	Mage::getSingleton('core/session', array('name' =&gt; 'frontend'));
 }
?&gt;

&lt;?php get_header(); ?&gt;
&lt;!-- Magento's custom greeting --&gt;
&lt;div style=&quot;font-size: 15px; margin-bottom: 15px; border-bottom: 1px solid #000; padding-bottom: 10px;&quot;&gt;
&lt;?php
if(class_exists('Mage')){
	$session = Mage::getSingleton(&quot;customer/session&quot;);
	$magento_message = &quot;Welcome &quot;;
	// Generate a personalize greeting
	if($session-&gt;isLoggedIn()){
		$magento_message .= $session-&gt;getCustomer()-&gt;getData('firstname').' ';
		$magento_message .= $session-&gt;getCustomer()-&gt;getData('lastname').'!';
	}else{
		$magento_message .= &quot;Guest!&quot;;
	}

	echo $magento_message;
}
?&gt;
&lt;/div&gt;
&lt;!-- End of Magento's custom greeting --&gt;</pre>
<p>The purpose of the code change above is to display a ?Welcome [customer name here]? when a customer is logged in, and show ?Welcome Guest? when they are not. <strong>Make sure that if you&#8217;re going to use any Magento related script in your code, always write it within the following if condition:</strong></p>
<pre class="brush: php; title: ; notranslate">if(class_exists('Mage')){
	// Write your Magento codes here
}</pre>
<p>This will prevent your page or theme files from breaking up if in case the plugin is deactivated, not working or if Mage.php can&#8217;t be found.</p>
<p>Open user.php file found at following address below:</p>
<pre>path-to-your-root-htdocs/wordpress/wp-includes/user.php</pre>
<p>Locate the function wp_authenticate_username_password()  and find the similar code below. I found mine at line 108.</p>
<pre class="brush: php; first-line: 108; title: ; notranslate">	if ( !wp_check_password($password, $userdata-&gt;user_pass, $userdata-&gt;ID) )
		return new WP_Error('incorrect_password', sprintf(__('&lt;strong&gt;ERROR&lt;/strong&gt;: Incorrect password. &lt;a href=&quot;%s&quot; title=&quot;Password Lost and Found&quot;&gt;Lost your password&lt;/a&gt;?'), site_url('wp-login.php?action=lostpassword', 'login')));</pre>
<p>Right after the code above, add the following code starting at line 111 to make it similar to the code below. This update allows us to run the login request of Magento within WordPress:</p>
<pre class="brush: php; first-line: 108; title: ; notranslate">	if ( !wp_check_password($password, $userdata-&gt;user_pass, $userdata-&gt;ID) )
		return new WP_Error('incorrect_password', sprintf(__('&lt;strong&gt;ERROR&lt;/strong&gt;: Incorrect password. &lt;a href=&quot;%s&quot; title=&quot;Password Lost and Found&quot;&gt;Lost your password&lt;/a&gt;?'), site_url('wp-login.php?action=lostpassword', 'login')));
	// Start Magento
	if(class_exists('Mage')){
		Mage::getSingleton('core/session', array('name' =&gt; 'frontend'));
		$session = Mage::getSingleton(&quot;customer/session&quot;);
		try{
			$login = $session-&gt;login($username, $password);
		}catch(Exception $e){
			// Do nothing
		}
	}</pre>
<p>Finally, to call the Magento&#8217;s logout function, locate the file below and open it:</p>
<pre>path-to-your-root-htdocs/wordpress/wp-login.php</pre>
<p>Find the switch case statement at line 352. Add the necessary code to make it similar to the code below and save it:</p>
<pre class="brush: plain; first-line: 352; title: ; notranslate">switch ($action) {

case 'logout' :
	check_admin_referer('log-out');
	// Start Magento
	if(class_exists('Mage')){
		Mage::getSingleton('core/session', array('name' =&gt; 'frontend'));
		Mage::getSingleton(&quot;customer/session&quot;)-&gt;logout();
	}
	wp_logout();</pre>
<p>Now test your WordPress by accessing the homepage at http://localhost/wordpress/. It should display the &#8216;Welcome Guest&#8217; similar to the image below with a cookie named as &#8216;frontend&#8217; in your Firebug cookie tab. That is your Magento cookie.</p>
<div id="attachment_304" class="wp-caption aligncenter" style="width: 499px"><a href="http://mysillypointofview.files.wordpress.com/2010/04/test_wordpress_home.png"><img class="size-full wp-image-304 " title="A Test WordPress homepage showing the default welcome message for Magento" src="http://mysillypointofview.files.wordpress.com/2010/04/test_wordpress_home.png" alt="A Test WordPress homepage showing the default welcome message for Magento" width="489" height="516" /></a><p class="wp-caption-text">A Test WordPress homepage showing the default welcome message for Magento</p></div>
<p>Clicking the login for WordPress redirects us to the login form like the one below while still showing the &#8216;frontend&#8217; cookie. Since I have a customer with same credentials on both Magento (Customer) and WordPress (set as Subscriber), all I have to do is to use the username and password to login in the form below.</p>
<div id="attachment_306" class="wp-caption aligncenter" style="width: 496px"><a href="http://mysillypointofview.files.wordpress.com/2010/04/test_wordpress_login.png"><img class="size-full wp-image-306 " title="A Test WordPress login page with a generated Magento cookie" src="http://mysillypointofview.files.wordpress.com/2010/04/test_wordpress_login.png" alt="A Test WordPress login page with a generated Magento cookie" width="486" height="455" /></a><p class="wp-caption-text">A Test WordPress login page with a generated Magento cookie</p></div>
<p>At this point, your Magento session should be running with an active customer session. To check if it does, go back to your homepage by clicking the top header text or going to http://localhost/wordpress/. It should display now the welcome message with your customer&#8217;s name.</p>
<div id="attachment_308" class="wp-caption aligncenter" style="width: 496px"><a href="http://mysillypointofview.files.wordpress.com/2010/04/test_wordpress_with_active_customer.png"><img class="size-full wp-image-308 " title="A Test WordPress homepage showing the customer's name in the welcome message" src="http://mysillypointofview.files.wordpress.com/2010/04/test_wordpress_with_active_customer.png" alt="A Test WordPress homepage showing the customer's name in the welcome message" width="486" height="500" /></a><p class="wp-caption-text">A Test WordPress homepage showing the customer&#039;s name in the welcome message</p></div>
<p>For those who will use this plugin, let me know the version of WordPress and Magento you&#8217;re using so I can keep track of the list of versions in which this plugin is compatible. <del datetime="2010-05-12T06:31:45+00:00">Until such time that the plugin is moved to the Official WordPress Plugin repository, I&#8217;ll accept and answer inquiries here thru comment/feedback form below.</del> Mage Enabler is now available in the Official WordPress Plugin repository. <a href="http://wordpress.org/extend/plugins/mage-enabler/">Get it here!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mysillypointofview.richardferaro.com/2010/05/11/mage-enabler/feed/</wfw:commentRss>
		<slash:comments>182</slash:comments>
		</item>
		<item>
		<title>How to run Magento (version 1.4.0.1) session into an external site?</title>
		<link>http://mysillypointofview.richardferaro.com/2010/03/25/how-to-run-magento-version-1-4-0-1-session-to-external-site/</link>
		<comments>http://mysillypointofview.richardferaro.com/2010/03/25/how-to-run-magento-version-1-4-0-1-session-to-external-site/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 14:20:00 +0000</pubDate>
		<dc:creator>Richard Feraro</dc:creator>
				<category><![CDATA[Feeling guru]]></category>
		<category><![CDATA[Techie Daw]]></category>
		<category><![CDATA[e-commerce]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://mysillypointofview.wordpress.com/?p=269</guid>
		<description><![CDATA[This post is an update for my blog entry on how to extend the Magento session to an external site but instead of using the version 1.2.1.2, I used the the latest stable version as of this writing which is version 1.4.0.1. The script below also implements the login() and logout() method the Magento way [...]]]></description>
			<content:encoded><![CDATA[<p>This post is an update for my blog entry on <a href="http://mysillypointofview.richardferaro.com/2009/04/13/how-to-run-magento-session-to-an-external-site/">how to extend the Magento session to an external site</a> but instead of using the version 1.2.1.2, I used the the latest stable version as of this writing which is version 1.4.0.1. The script below also implements the <strong>login()</strong> and <strong>logout()</strong> method the Magento way as well as extracting the customer data (firstname and lastname) using <strong>getCustomer()</strong> method.</p>
<p><span id="more-269"></span>
<pre class="brush: php; title: ; notranslate">&lt;?php
// Include Magento application
require_once ( &quot;/var/www/your-magento-directory/app/Mage.php&quot; );
umask(0);

// Initialize Magento
Mage::app(&quot;default&quot;);

// You have two options here,
// &quot;frontend&quot; for frontend session or &quot;adminhtml&quot; for admin session
Mage::getSingleton(&quot;core/session&quot;, array(&quot;name&quot; =&gt; &quot;frontend&quot;));
$session = Mage::getSingleton(&quot;customer/session&quot;);

if(!isset($_REQUEST['action'])) {
	$_REQUEST['action'] = '';
}

switch($_REQUEST['action']){
	case &quot;login&quot;:
		try{
			// Do login request.
			// I know, there are ways to sanitize the form.
			// But for simplicity's sake, let's assume we already
			// did our homework regarding the matter.
			$login = $session-&gt;login($_POST['username'],$_POST['password']);
		}catch(Exception $e){
			// Do something for the error message
			$message = $e-&gt;getMessage();
		}

		header(&quot;location: index.php&quot;);

		break;
	case &quot;logout&quot;:
		// Execute the logout request
		$session-&gt;logout();
		header(&quot;location: index.php&quot;);

		break;
	default:
		// If the customer is not logged in, show login form
		// else, show logout link
		if(!$session-&gt;isLoggedIn()){
		?&gt;
			&lt;html&gt;
			&lt;head&gt;
			&lt;title&gt;External Page for Magento&lt;/title&gt;
			&lt;/head&gt;
			&lt;body&gt;
			&lt;h3&gt;Login here&lt;/h3&gt;
			&lt;form method=&quot;POST&quot; action=&quot;index.php&quot;&gt;
			Username &lt;input type=&quot;text&quot; name=&quot;username&quot; size=&quot;10&quot; /&gt;
			Password &lt;input type=&quot;password&quot; name=&quot;password&quot; size=&quot;10&quot; /&gt;
			&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;login&quot; /&gt;
			&lt;input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;login&quot; /&gt;
			&lt;/form&gt;
			&lt;/body&gt;
			&lt;/html&gt;
&lt;?php
		}else{
			$firstname = $session-&gt;getCustomer()-&gt;getData('firstname');
			$lastname = $session-&gt;getCustomer()-&gt;getData('lastname');
			echo &quot;Welcome &quot;.$firstname.&quot; &quot;.$lastname.&quot;!&lt;br&gt;&quot;;
			echo &quot;You're currently logged in &quot;;
			echo &quot;[ &lt;a href=\&quot;index.php?action=logout\&quot;&gt;click here to logout&lt;/a&gt; ]&quot;;
		}
}
?&gt;
</pre>
<p>Just copy the whole script and save it as <strong>index.php</strong> and run the script.</p>
]]></content:encoded>
			<wfw:commentRss>http://mysillypointofview.richardferaro.com/2010/03/25/how-to-run-magento-version-1-4-0-1-session-to-external-site/feed/</wfw:commentRss>
		<slash:comments>88</slash:comments>
		</item>
		<item>
		<title>How to Fix Magento&#8217;s Admin Login Failing (no error message) on Localhost</title>
		<link>http://mysillypointofview.richardferaro.com/2010/03/24/how-to-fix-magentos-admin-login-failing-no-error-message-on-localhost/</link>
		<comments>http://mysillypointofview.richardferaro.com/2010/03/24/how-to-fix-magentos-admin-login-failing-no-error-message-on-localhost/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 12:28:23 +0000</pubDate>
		<dc:creator>Richard Feraro</dc:creator>
				<category><![CDATA[Feeling guru]]></category>
		<category><![CDATA[Techie Daw]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://mysillypointofview.wordpress.com/?p=225</guid>
		<description><![CDATA[You want to install a new Magento instance (version 1.4.0.1 at the time of this writing) in your machine. You followed every steps from downloading up to the setting up of your admin account. Everything went fine so you assumed you&#8217;re good to go. You tried to login using your admin account&#8230; nothing happened. You [...]]]></description>
			<content:encoded><![CDATA[<p>You want to install a new Magento instance (version 1.4.0.1 at the time of this writing) in your machine. You followed every steps from downloading up to the setting up of your admin account. Everything went fine so you assumed you&#8217;re good to go. You tried to login using your admin account&#8230; nothing happened. You tried again&#8230; Same login screen with no error whatsoever. You wonder what went wrong. You checked the files and the database as well as clearing the cache. You even tried resetting your account&#8217;s password found in the Magento&#8217;s <em>admin_user</em> table using the MD5 function thru phpMyAdmin but to no avail. You gave up and tried to reinstall everything only to be greeted by the very same login screen after clicking the Login button.</p>
<p><span id="more-225"></span>The real problem lies when a Magento instance is running through a localhost and tries to create a cookie, but fails to do so because it requires a domain and localhost is not a true domain (thanks to <a href="http://www.blogger.com/profile/14751715706838377391">Mohammad Abdul Momin Arju</a> for pointing this out in his <a href="http://arjudba.blogspot.com/2009/04/after-installing-magento-cant-log-in-to.html">blog</a>). You can do a simple check to validate this by using Firefox and Firebug to check if a cookie is being generated by the Magento&#8217;s Admin Panel login page.</p>
<div id="attachment_245" class="wp-caption alignnone" style="width: 476px"><a href="http://mysillypointofview.files.wordpress.com/2010/03/magento-admin-login-no-cookie1.png"><img class="size-full wp-image-245    " title="magento-admin-login-no-cookie" src="http://mysillypointofview.files.wordpress.com/2010/03/magento-admin-login-no-cookie1.png" alt="Magento's Admin Panel Login without cookie being generated upon loading" width="466" height="284" /></a><p class="wp-caption-text">Magento&#039;s Admin Panel Login without a cookie being generated upon loading</p></div>
<p>At this point, we have to edit the core files without breaking the functionality behind this domain checking feature of Magento. <del datetime="2010-05-11T14:49:18+00:00">To do this, open the following file:</del></p>
<p>Copy the <strong>Varien.php</strong> core file which can be found below:</p>
<pre>app\code\core\Mage\Core\Model\Session\Abstract\Varien.php</pre>
<p>where we assumed that your root directory is <strong>htdocs</strong> and inside it is your <strong>magento</strong> folder.</p>
<p>Paste it in the Magento &#8216;local&#8217; folder which can be found below (create needed folders if it doesn&#8217;t exists) and open the file for editing:</p>
<pre>app\code\local\Mage\Core\Model\Session\Abstract\Varien.php</pre>
<p>Go to line 96 or locate the code similar below:</p>
<pre class="brush: php; first-line: 96; title: ; notranslate">if (isset($cookieParams['domain'])) {
    $cookieParams['domain'] = $cookie-&gt;getDomain();
}</pre>
<p>Replace the code found in line 96 with this one:</p>
<pre class="brush: php; first-line: 96; title: ; notranslate">if (isset($cookieParams['domain']) &amp;&amp; !in_array(&quot;127.0.0.1&quot;, self::getValidatorData())) {</pre>
<p><strong>For Apple machines or other operating system, try what Nirav did found in his <a href="#commententry-676">comment</a>.</strong></p>
<p>The purpose of this code change is to disable the Magento&#8217;s domain checking only if it is accessed via localhost and run as usual if it is being accessed thru a valid domain.</p>
<p>Clear your browser&#8217;s cookies to start with a clean slate then clear the Magento cache by deleting all the contents of the following folder:</p>
<pre>var\cache</pre>
<p>Access the Magento Admin Panel login again thru localhost while your firebug&#8217;s cookie tab being on (http://localhost:8080/magento/index.php/admin/). It should display something similar to the image below indicating that a cookie with an adminhtml name has been generated.</p>
<div id="attachment_254" class="wp-caption alignnone" style="width: 476px"><a href="http://mysillypointofview.files.wordpress.com/2010/03/magento-admin-login-with-cookie.png"><img class="size-full wp-image-254     " title="magento-admin-login-with-cookie" src="http://mysillypointofview.files.wordpress.com/2010/03/magento-admin-login-with-cookie.png" alt="Magento's Admin Panel Login with a cookie being generated upon loading" width="466" height="282" /></a><p class="wp-caption-text">Magento&#039;s Admin Panel Login showing a cookie &#039;adminhtml&#039; generated after loading</p></div>
<p>At this point you should be able to login now with your admin username and password using localhost as your domain.</p>
]]></content:encoded>
			<wfw:commentRss>http://mysillypointofview.richardferaro.com/2010/03/24/how-to-fix-magentos-admin-login-failing-no-error-message-on-localhost/feed/</wfw:commentRss>
		<slash:comments>265</slash:comments>
		</item>
		<item>
		<title>How to add a product into Magento shopping cart from an external site?</title>
		<link>http://mysillypointofview.richardferaro.com/2009/04/27/how-to-add-a-product-into-magento-from-an-external-site/</link>
		<comments>http://mysillypointofview.richardferaro.com/2009/04/27/how-to-add-a-product-into-magento-from-an-external-site/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 06:28:17 +0000</pubDate>
		<dc:creator>Richard Feraro</dc:creator>
				<category><![CDATA[Feeling guru]]></category>
		<category><![CDATA[Techie Daw]]></category>
		<category><![CDATA[e-commerce]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://mysillypointofview.wordpress.com/?p=128</guid>
		<description><![CDATA[Yes, I know. This topic has already been discussed here. But it seems the article isn&#8217;t really helpful for those people who would integrate Magento into a custom website because it will redirect the page to Magento&#8217;s default web store provided in the installation. The technique I&#8217;ll discuss here assumes that you know HTML and [...]]]></description>
			<content:encoded><![CDATA[<p>Yes, I know. This topic has already been discussed <a title="Adding a Product to the Cart via Querystring" href="http://www.magentocommerce.com/wiki/adding_a_product_to_the_cart_via_querystring" target="_blank">here</a>. But it seems the article isn&#8217;t really helpful for those people who would integrate Magento into a custom website because it will redirect the page to Magento&#8217;s default web store provided in the installation. The technique I&#8217;ll discuss here assumes that you know HTML and ofcourse familiar with Object Oriented Programming (OOP) in PHP.</p>
<p><span id="more-128"></span>Let&#8217;s start.</p>
<p>We begin our <strong>index.php</strong> page with a HTML form having one (1) textbox for quantity and a submit button.</p>
<pre class="brush: xml; title: ; notranslate">&lt;form action=&quot;process.php&quot;&gt;
Product name: T-shirt &lt;br&gt;
Quantity: &lt;input type=&quot;text&quot; name=&quot;qty[&lt;?=$productID?&gt;]&quot;&gt;
&lt;input type=&quot;submit&quot; value=&quot;Add to Cart&quot;&gt;
&lt;/form&gt;</pre>
<p>where <strong>$productID</strong> is the ID of the product that you want to add into your shopping cart and <strong>process.php</strong> is the file that will do the processing of the form. Also upon submission of the form, the qty field will pass the value into an array format similar to one below:</p>
<pre class="brush: xml; title: ; notranslate">&quot;qty&quot; = array(12345 =&gt; 1)</pre>
<p>where</p>
<blockquote><p><strong>qty</strong> is the field name<br />
<strong>12345</strong> is the product ID and<br />
<strong>1</strong> is the qty value</p></blockquote>
<p>This will be the content of <strong>process.php</strong> file:</p>
<p>Include the Mage.php file on top of the process.php. <a href="http://mysillypointofview.richardferaro.com/2009/04/13/how-to-run-magento-session-to-an-external-site/" target="_blank">Click here to see how.</a><br />
Then proceed with the php script below:</p>
<pre class="brush: php; title: ; notranslate">// continuation of process.php
$items = $_POST[&quot;qty&quot;];

// get the current Magento cart
$cart = Mage::getSingleton('checkout/cart');

foreach($items as $key =&gt; $value)
{
   // call the Magento catalog/product model
   $product = Mage::getModel('catalog/product')
                     // set the current store ID
                     -&gt;setStoreId(Mage::app()-&gt;getStore()-&gt;getId())
                     // load the product object
                     -&gt;load($key);

   // start adding the product
   $cart-&gt;addProduct($product, array('qty' =&gt; $value));
   // save the cart
   $cart-&gt;save();

   // very straightforward, set the cart as updated
   Mage::getSingleton('checkout/session')-&gt;setCartWasUpdated(true);
}

// redirect to index.php
header(&quot;Location: index.php&quot;);
</pre>
<p>That&#8217;s it! I didn&#8217;t add the end tag for php since <a href="http://framework.zend.com/manual/en/coding-standard.php-file-formatting.html#coding-standard.php-file-formatting.general" target="_blank">it isn&#8217;t required for pure php file</a>. I included alot of comments within the code to explain how each line works. If it causes you some problems, just remove the comments <img src='http://mysillypointofview.richardferaro.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://mysillypointofview.richardferaro.com/2009/04/27/how-to-add-a-product-into-magento-from-an-external-site/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>How to delete a quote in Magento?</title>
		<link>http://mysillypointofview.richardferaro.com/2009/04/13/how-to-delete-a-quote-in-magento/</link>
		<comments>http://mysillypointofview.richardferaro.com/2009/04/13/how-to-delete-a-quote-in-magento/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 08:59:33 +0000</pubDate>
		<dc:creator>Richard Feraro</dc:creator>
				<category><![CDATA[Feeling guru]]></category>
		<category><![CDATA[Techie Daw]]></category>
		<category><![CDATA[e-commerce]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://mysillypointofview.wordpress.com/?p=50</guid>
		<description><![CDATA[If you&#8217;re using an external site with Magento as a backend for e-commerce functionality, you will notice that the shopping cart items doesn&#8217;t get deleted after you checkout. Actually in Magento, a shopping cart is a quote. So to remove everything in the shopping cart, you must delete the quote currently used by the user. [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re using an external site with Magento as a backend for e-commerce functionality, you will notice that the shopping cart items doesn&#8217;t get deleted after you checkout. Actually in Magento, a shopping cart is a quote. So to remove everything in the shopping cart, you must delete the quote currently used by the user. To do this, follow the code below:</p>
<p><span id="more-50"></span>First, insert the Magento app snippets which can be found <a href="2009/04/13/how-to-run-magento-session-to-an-external-site/">here</a></p>
<p>then use the code below to delete a quote:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php
$quoteID = Mage::getSingleton(&quot;checkout/session&quot;)-&gt;getQuote()-&gt;getId();

if($quoteID)
{
    try {
        $quote = Mage::getModel(&quot;sales/quote&quot;)-&gt;load($quoteID);
        $quote-&gt;setIsActive(false);
        $quote-&gt;delete();

        return &quot;cart deleted&quot;;
    } catch(Exception $e) {
        return $e-&gt;getMessage();
    }
}else{
    return &quot;no quote found&quot;;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mysillypointofview.richardferaro.com/2009/04/13/how-to-delete-a-quote-in-magento/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>How to run Magento session into an external site?</title>
		<link>http://mysillypointofview.richardferaro.com/2009/04/13/how-to-run-magento-session-to-an-external-site/</link>
		<comments>http://mysillypointofview.richardferaro.com/2009/04/13/how-to-run-magento-session-to-an-external-site/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 08:02:27 +0000</pubDate>
		<dc:creator>Richard Feraro</dc:creator>
				<category><![CDATA[Feeling guru]]></category>
		<category><![CDATA[Techie Daw]]></category>
		<category><![CDATA[e-commerce]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://mysillypointofview.wordpress.com/?p=52</guid>
		<description><![CDATA[Recently I received a programming task requiring to use Magento as backend system while implementing its e-commerce functionality to a website created using CodeIgniter framework. After reading a book related to the software mentioned, I found this piece of code that will enable me to use all Magento&#8217;s power into my custom website: That&#8217;s it! [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I received a programming task requiring to use Magento as backend system while implementing its e-commerce functionality to a website created using CodeIgniter framework. After reading a book related to the software mentioned, I found this piece of code that will enable me to use all Magento&#8217;s power into my custom website:</p>
<p><span id="more-52"></span></p>
<pre class="brush: php; title: ; notranslate">&lt;?php
// Include Magento application
require_once ( &quot;/var/www/your-magento-directory/app/Mage.php&quot; );
umask(0);

// Initialize Magento
Mage::app(&quot;default&quot;);

// You have two options here,
// &quot;frontend&quot; for frontend session or &quot;adminhtml&quot; for admin session
Mage::getSingleton(&quot;core/session&quot;, array(&quot;name&quot; =&gt; &quot;frontend&quot;));</pre>
<p>That&#8217;s it! You can now use the internal classes and functions of Magento into your site. For example, the code below validates whether a customer is logged in or not by checking the Magento session:</p>
<pre class="brush: php; title: ; notranslate">$session = Mage::getSingleton(&quot;customer/session&quot;);

if($session-&gt;isLoggedIn())
{
    echo &quot;Logged in&quot;;
}else{
    echo &quot;Not logged in&quot;;
}</pre>
<p><strong>** Updated **</strong><br />
For users of Magento version 1.4.0.1, <a href="http://mysillypointofview.wordpress.com/2010/03/25/how-to-run-magento-version-1-4-0-1-session-to-external-site/">click here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mysillypointofview.richardferaro.com/2009/04/13/how-to-run-magento-session-to-an-external-site/feed/</wfw:commentRss>
		<slash:comments>59</slash:comments>
		</item>
	</channel>
</rss>

