<?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>Linden LAN &#187; Magento</title>
	<atom:link href="http://www.lindenlan.net/tag/magento/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lindenlan.net</link>
	<description></description>
	<lastBuildDate>Sat, 29 Nov 2014 04:54:20 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>How To Simultaneously Add Multiple Products To A Magento Shopping Cart</title>
		<link>http://www.lindenlan.net/2009/09/27/how-to-simultaneously-add-multiple-products-to-a-magento-shopping-cart/</link>
		<comments>http://www.lindenlan.net/2009/09/27/how-to-simultaneously-add-multiple-products-to-a-magento-shopping-cart/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 02:01:38 +0000</pubDate>
		<dc:creator><![CDATA[Brian]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.lindenlan.net/?p=349</guid>
		<description><![CDATA[This post is a bit overdue considering the project for which I did this was completed months ago. I finally got around to documenting it. Magento’s product list view lets customers add products to the shopping cart one at a time. The client wanted customers to be able to add multiple products to the shopping [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>This post is a bit overdue considering the project for which I did this was completed months ago.  I finally got around to documenting it.  Magento’s product list view lets customers add products to the shopping cart one at a time.  The client wanted customers to be able to add multiple products to the shopping cart simultaneously.  Given the time constraints for the projects, I created an ad hoc AJAX method to accomplish this feature request.</p>
<p><span id="more-349"></span></p>
<p>Adding a product to a Magento (ver. 1.3.1) shopping cart is accomplished through an HTTP GET request.  It will look like or similar to this:</p>
<pre class="brush: sh">
/path/to/app/checkout/cart/add?product=[id]&amp;qty=[qty]
</pre>
<p>That URL is output by the template helper:</p>
<pre class="brush: php">
$this-&gt;getAddToCartUrl($_product)
</pre>
<p>Since adding a product to the shopping cart is nothing more than a GET request, then all that needs to be done is queue up the URLs of the desired products, make each request in order, and then reload the page when done.</p>
<p>First, in app/design/frontend/
<package>/
<theme>/template/catalog/product/list.html, I first added checkboxes to allow customers to select which products they want and also hidden fields for storing the URLs to add the product and text fields for the quantity. </p>
<pre class="brush: php">
&lt;input type=&quot;checkbox&quot; class=&quot;input-checkbox add&quot; name=&quot;add_&lt;?php echo $_iterator; ?&gt;&quot; id=&quot;add_&lt;?php echo $_iterator; ?&gt;&quot; /&gt;
&lt;input type=&quot;hidden&quot; name=&quot;url_&lt;?php echo $_iterator; ?&gt;&quot; id=&quot;url_&lt;?php echo $_iterator; ?&gt;&quot; value=&quot;&lt;?php echo $this-&gt;getAddToCartUrl($_product) ?&gt;&quot; /&gt;
&lt;?php if(!$_product-&gt;isGrouped()): ?&gt;
     &lt;input type=&quot;text&quot; class=&quot;input-text qty&quot; name=&quot;qty_&lt;?php echo $_iterator; ?&gt;&quot; id=&quot;qty_&lt;?php echo $_iterator; ?&gt;&quot; maxlength=&quot;12&quot; value=&quot;&lt;?php echo $this-&gt;getMinimalQty($_product) ?&gt;&quot; /&gt;
&lt;?php endif; ?&gt;
</pre>
<p>I added this code within the loop that generate the HTML for the product line items for the list.  Next, I added the JavaScript that does the actual processing, also within the list section right after the script block that contains: <code>decorateList('products-list', 'none-recursive')</code>.</p>
<pre class="brush: javascript">
&lt;script type=&quot;text/javascript&quot;&gt;
    function processNext(urls, i) {
        var next = i + 1;
        $(&#039;processing-text&#039;).update(&#039;Processing item &#039; + next);
        if (next &lt; urls.size()) {
            new Ajax.Request(urls[i], {
              method: &#039;get&#039;,
              onComplete: function(transport) {
                processNext(urls, next);
              }
            });
        } else {
            new Ajax.Request(urls[i], {
              method: &#039;get&#039;,
              onComplete: function(transport) {
                window.location.reload();
              }
            });
        }
    }

    function addItemsToCart() {
        $(&#039;add-items-to-cart&#039;).hide();
        $(&#039;waiting&#039;).show();
        
        var addToCartUrls = [];
        $$(&#039;input.add&#039;).each(function(e){ 
            if(e.checked == true) {
                var id = e.readAttribute(&#039;id&#039;).split(&#039;_&#039;)[1];
                var qty = Number($(&#039;qty_&#039; + id).value);
                if (qty &lt; 1) qty = 1;
                addToCartUrls.push($(&#039;url_&#039; + id).value + &#039;qty/&#039; + qty);
            }
        });
        
        if (addToCartUrls.size() &gt; 0) {
            processNext(addToCartUrls, 0);
        } else {
            $(&#039;add-items-to-cart&#039;).show();
            $(&#039;waiting&#039;).hide();
            alert(&#039;Please check off the items you want to add.&#039;);
        }
    }
&lt;/script&gt;
</pre>
<p>At the bottom of the list I added a submit button.</p>
<pre class="brush: php">
&lt;div style=&quot;margin-bottom:5px; text-align:right;&quot;&gt;&lt;button id=&quot;add-items-to-cart&quot; class=&quot;form-button&quot; onclick=&quot;addItemsToCart()&quot;&gt;&lt;span&gt;&lt;?php echo $this-&gt;__(&#039;Add Items to Cart&#039;) ?&gt;&lt;/span&gt;&lt;/button&gt;&lt;div id=&quot;waiting&quot; style=&quot;height:22px; display:none; line-height:22px;&quot;&gt;&lt;span id=&quot;processing-text&quot;&gt;Processing...&lt;/span&gt; &lt;img src=&quot;&lt;?php echo $this-&gt;getSkinUrl().&#039;images/wait22trans.gif&#039;; ?&gt;&quot; width=&quot;22&quot; height=&quot;22&quot; style=&quot;display:inline; vertical-align:middle;&quot;/&gt;&lt;/div&gt;&lt;/div&gt;
</pre>
<p>Clicking the button calls the function <code>addItemsToCart()</code>.  The function hides the button to prevent a double click and unhides the status message.  Next, the function determines which checkboxes are checked.  For each checked checkbox, the function finds the corresponding URL field and quantity field, concatenates the two values, and stores the new URL in an array.  If the length of the array is greater than 0, then the function calls <code>processNext()</code>, otherwise it displays an error message and resets the submit button.</p>
<p>The function <code>processNext()</code> first updates the processing message.  The function takes the array of URLs and an index, and then creates an AJAX GET request using the URL at the given index in the array.  If the AJAX request completes, it calls processNext() with the same array but with an incremented index while the index is less than the array length.  If the incremented index is greater than the array length, then that ends the processing and the function reloads the page.</p>
<p>That’s it.  If there is anything wrong with the code, it assumes that all the GET requests will complete.  Unfortunately, given the time constraints there was no time to account for the scenario where a GET request fails.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lindenlan.net/2009/09/27/how-to-simultaneously-add-multiple-products-to-a-magento-shopping-cart/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>How To Fake a Magento Subpage</title>
		<link>http://www.lindenlan.net/2009/04/21/how-to-fake-a-magento-subpage/</link>
		<comments>http://www.lindenlan.net/2009/04/21/how-to-fake-a-magento-subpage/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 14:52:50 +0000</pubDate>
		<dc:creator><![CDATA[Admin]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.lindenlan.net/?p=308</guid>
		<description><![CDATA[Magento, an open-source PHP ecommerce solution, has a very comprehensive feature list. However, its built-in CMS doesn’t support hierarchical pages. You can fake it, though. Let’s say you have a page with an SEF (search engine friendly) URL Identifier of “foo”. You’d like to have a subpage “bar” nested under foo. The CMS doesn’t let [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Magento, an open-source PHP ecommerce solution, has a very comprehensive feature list.  However, its built-in CMS doesn’t support hierarchical pages.  You can fake it, though.  </p>
<p><span id="more-308"></span></p>
<p>Let’s say you have a page with an SEF (search engine friendly) URL Identifier of “foo”.  You’d like to have a subpage “bar” nested under foo.  The CMS doesn’t let you create parent-child relationships, but Magento will let you include forward slashes in the SEF URL Identifier so that it is “foo/bar”.  </p>
<p>That’s the good news.  The bad news is if you want to use the breadcrumbs block, it won’t work out of the box.  The Magento CMS is flat, so the default breadcrumbs will always look like “Home / My Page Title.”  The optimal solution is to override the breadcrumbs module and parse the SEF URL Identifier and construct the breadcrumbs from that.  (I may write a post about it in the future so stay tuned.)  The good news for those designers out there, you don’t have to dive into code.  </p>
<p>Magento’s CMS has a feature where each page has a way to override its XML layout.  When you’re editing a page, go to the “Custom Design” tab.  There you’ll see a form field called “Layout Update XML”.  This is the key.  Here’s where you add XML to first unset the breadcrumbs block and then add it back in but with your specific breadcrumbs.  Here’s the code:</p>
<pre class="brush: html">
&lt;reference name=&quot;root&quot;&gt;
&lt;action method=&quot;unsetChild&quot;&gt;&lt;alias&gt;breadcrumbs&lt;/alias&gt;&lt;/action&gt;
&lt;/reference&gt;

&lt;reference name=&quot;root&quot;&gt;
&lt;block type=&quot;page/html_breadcrumbs&quot; name=&quot;breadcrumbs&quot; as=&quot;breadcrumbs&quot;&gt;
    &lt;action method=&quot;addCrumb&quot;&gt;
        &lt;crumbName&gt;home&lt;/crumbName&gt;
        &lt;crumbInfo&gt;&lt;label&gt;Home&lt;/label&gt;&lt;title&gt;Go to Home Page&lt;/title&gt;&lt;link&gt;/&lt;/link&gt;&lt;/crumbInfo&gt;
    &lt;/action&gt;             
    &lt;action method=&quot;addCrumb&quot;&gt;
        &lt;crumbName&gt;foo&lt;/crumbName&gt;
        &lt;crumbInfo&gt;&lt;label&gt;Foo&lt;/label&gt;&lt;title&gt;Foo&lt;/title&gt;&lt;link&gt;/foo/&lt;/link&gt;&lt;/crumbInfo&gt;
    &lt;/action&gt;             
    &lt;action method=&quot;addCrumb&quot;&gt;
        &lt;crumbName&gt;cms_page&lt;/crumbName&gt;
        &lt;crumbInfo&gt;&lt;label&gt;Bar&lt;/label&gt;&lt;title&gt;Bar&lt;/title&gt;&lt;/crumbInfo&gt;
    &lt;/action&gt;                  
&lt;/block&gt;
&lt;/reference&gt;
</pre>
<p>The first reference tells Magento to call the unset action on the root block to remove the original breadcrumbs.  The second reference tells Magento to add a new breadcrumbs block.  Then within that block it tells Magento to add three new breadcrumbs, one for “home”, one for “foo”, and another for “bar”.  crumbName is just a unique identifier.  Under crumbInfo, label is the link text, title is the hover text, and link is the URL.  You need to include the root forward slash.  The trailing slash is optional, but to be consistent with Magento you should include it.</p>
<p>And that’s all there is to it.  If you have a Magento site with lots of CMS subpages or pages that are deeply nested, then this method can get tedious.  That’s why I said the optimal solution is to override the breadcrumbs module in core as a local modification.  If you don’t have many CMS subpages and they’re only one-level deep, then this method is adequate.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lindenlan.net/2009/04/21/how-to-fake-a-magento-subpage/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
