Bogiecom.com
  • About
  • Magento
  • Sitecore
  • WordPress

Category Archives: Magento

Magento Top Navigation Sort Alphabetically

Posted on February 9, 2013 by bc-admin

If you are having a little trouble getting the top navigation to ignore the sort order and use alphabetical sort, here is one option you can use…

Consider the following code for a navigation menu…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
   <ul id="custom-menu">
    <?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories(true, true, false) ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>
    <ul style="width:940px;">
        <?php foreach($_categories as $_category): ?>
            <li>
                <b><a class="drop" href="<?php echo $_helper->getCategoryUrl($_category) ?>">
                    <?php echo $_category->getName() ?>
                </a></b>
                <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
 
                <?php
       $collection = $_category->getCollection();
                    $_subcategories = $_category->getChildrenCategories() ?>
                
                <?php if (count($_subcategories) > 0): ?>
                    <div class="dropdown_1column" style="width:235px;">
                        <?php foreach($_subcategories as $_subcategory): ?>
                            <div class="col_1">
                                <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
                                    <?php echo $_subcategory->getName() ?>
                                </a>
                            </div>
                        <?php endforeach; ?>
                        <div class="clr" clear="all"></div>
                    </div>
                <?php endif; ?>
            </li>
        <?php endforeach; ?>        
        </ul>                          
              
<?php endif; ?>

The problem is when you get down to the secondary level where it you use the getChildrenCategories(). This function only seems to respect sort order and doesn’t seem to have an option to sort by name. So if you look at the first call for the top level categories $_helper->getStoreCategories(true, true, false). The first parameter tells that section to sort by name.

Seeing as this only traverses the top level, the remaining subcategories are left unchanged. After searching all of the forums for a way around it, some people suggested changing the core file /Mage/Catalog/Model/Resource/Category.php and directly editing the getChildrenCategories() function. While this works… the best option would be to copy the contents of that function directly into the template, to keep it upgrade safe.

So this what that would like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
    <ul id="custom-menu">
    <?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories(true, true, false) ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>
    <ul style="width:940px;">
        <?php foreach($_categories as $_category): ?>
            <li>
                <b><a class="drop" href="<?php echo $_helper->getCategoryUrl($_category) ?>">
                    <?php echo $_category->getName() ?>
                </a></b>
                <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
 
                <?php
$collection = $_category->getCollection();
 
$_subcategories = $collection
->addAttributeToSelect('name')
->addAttributeToSelect('all_children')
->addAttributeToSelect('is_anchor')
->addAttributeToFilter('is_active', 1)
->addAttributeToSort('name','ASC')
->addIdFilter($_category->getChildren())
->setOrder('name', Varien_Db_Select::SQL_ASC)
->joinUrlRewrite()
->load();
//$_subcategories = $_category->getChildrenCategories() ?>
                
                <?php if (count($_subcategories) > 0): ?>
                    <div class="dropdown_1column" style="width:235px;">
                        <?php foreach($_subcategories as $_subcategory): ?>
                            <div class="col_1">
                                <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
                                    <?php echo $_subcategory->getName() ?>
                                </a>
                            </div>
                        <?php endforeach; ?>
                        <div class="clr" clear="all"></div>
                    </div>
                <?php endif; ?>
            </li>
        <?php endforeach; ?>        
        </ul>                          
              
<?php endif; ?>

So instead of calling $_subcategories = $_category->getChildrenCategories()… you just set the $_subcategories variable to the following:

1
2
3
4
5
6
7
8
9
10
$_subcategories = $collection
->addAttributeToSelect('name')
->addAttributeToSelect('all_children')
->addAttributeToSelect('is_anchor')
->addAttributeToFilter('is_active', 1)
->addAttributeToSort('name','ASC')
->addIdFilter($_category->getChildren())
->setOrder('name', Varien_Db_Select::SQL_ASC)
->joinUrlRewrite()
->load();

Posted in Magento, PHP | Tags: Alphabetical, getChildrenCategories, Magento, Sorting, Top Navigation |

Magento Custom Form Field Validators using Prototype (MySQL Date Format)

Posted on November 9, 2011 by bc-admin

Here I needed to make sure that the user input was formatted correctly for a MySQL database. The javascript calendar code was set to automatically input the date into the text field in the correct format, but the user still had the option to type it in manually. This was the Prototype validator I used to verify that the user had entered it correctly as ‘YYYY-MM-DD’:

1
2
3
4
5
<script type="text/javascript">
  Validation.add('required-date-format','Please Enter date as YYYY-MM-DD. Click the calendar icon to select a date.', function(v) {
       return  !Validation.get('IsEmpty').test(v) && /^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9])$/.test(v);  });
       var warrantyregistrationForm = new VarienForm('warrantyregistrationForm', true);
</script>

Posted in Custom Field Validator, Date Format, Magento, MySQL | Leave a comment |

Magento and WordPress Integration – A Couple of Options

Posted on September 8, 2009 by bc-admin

Lately, there certainly has been a lot of buzz around the thought of combining WordPress and Magento.  If you enjoy using WordPress for your CMS, but want to use Magento as your E-Commerce platform here are some options for you.

Lucky for most Magento users, there is an extension that will integrate Magento and WordPress with minimal effort. You may find the extension as well as the installation instructions here: Lazzymonks WordPress Integration 2.61

Personally, the extension did not offer what I was looking for, which was control over the SEO permalinks function in WordPress.  However, in the future the Lazzymonks extension may offer the ability to pick whatever permalinks setting you want in WordPress. 

So, where I started was at the following tutorial: Tutorial: Integrating 3rd Party CMS Content Within Magento. 

The tutorial was originally written for Expression Engine, but could be used for any CMS, including WordPress.  I was able to successfully integrate Magento and WordPress starting with the tutorial above.  However, there were some additional changes that had to be incorporated to meet the needs of my organization.

For one, I needed to make sure the RSS feeds out of WordPress could be easily viewed from the integration.  With the default integration above, this was not necessarily possible depending upon your site’s folder structure.  However, with a few lines of code, I was able to easily navigate from the header links generated by WordPress.

Another issue was the WordPress header information.  This required editing the Magento template to accomodate for the WordPress header information.  Most importantly for me, I wanted the WordPress page title to be the title of the Magento page.  This was possible by altering the Magento page template that would house the WordPress section of the website by excluding the title tags. At this point the WordPress title would begin to show up in the browser.

Then lastly, I had to find a WordPress template to fit the Magento template. Then edit the WordPress template until it looked good inside Magento.

And that was it.  Not so bad.  I’m sure there are some more/better possibilites on how to integrate WordPress and Magento, but for the time being this has worked for me.

Posted in Integration, Magento, Magento Third Party CMS Integration, Wordpress | Leave a comment |

Pages

  • About
  • Magento
  • Sitecore
  • WordPress

Archives

  • January 2017
  • December 2013
  • November 2013
  • February 2013
  • January 2013
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • November 2011
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • September 2009

Categories

  • .NET
  • Air Force
  • Apache Configuration
  • Bash
  • C#
  • Comma-Delimited
  • Custom Field Validator
  • Date Format
  • Dump Files
  • Files
  • Grep
  • Grooveshark
  • HTML
  • Image Resizing
  • Imagick
  • Integration
  • jQuery
  • Konami Code
  • Linux
  • Magento
  • Magento Third Party CMS Integration
  • Mini Shuttle
  • Miva Merchant 5.5
  • MySQL
  • PHP
  • Powershell
  • Regular Expressions
  • Rename-Item
  • Sed
  • Shell Scripting
  • Sitecore
  • Strings
  • Uncategorized
  • Updating Product Attributes
  • Video Games
  • Wordpress
  • X-37
  • XML
  • YUI Konami Event

CyberChimps WordPress Themes

© 2008 - 2016 Bogiecom.com