Archive

Posts Tagged ‘Magento’

How to Detect if the Page is Secure in a Magento Template?

October 22nd, 2009
Comments Off

When you are designing a Magento template it is easy to overlook a simple fact: most links should not be hard-coded and you should always use the methods that are available for you like getSkinUrl() and getJsUrl(). In addition to pointing to the right root folder, these methods also point to the secure or unsecure URLs, ‘https’ and ‘http’ respectively. However, how can you detect if a URL needs to be secured or not?

herring-hall-marvin-safe

In a recent Magento project, I needed to do exactly that: find out if we are in secure or in a non secure page and point to the right jQuery file on Google CDN’s. Here is the code:

<?php if(Mage::app()->getStore()->isCurrentlySecure()): ?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script> 
<?php else: ?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script> 
<?php endif;  ?>

The key method here is the Mage::app()->getStore()->isCurrentlySecure().

Reblog this post [with Zemanta]

Magento , ,

Magento’s massAction for Custom Plugins

October 8th, 2009
Comments Off

Ever wanted to allow your users to make mass action on your Magento Custom Plugin records? The good news is that it is built in to the Magento Admin Panel and is available at the community edition. The bad news is that there is absolutely no documentation on how to use it. Here are the 3 steps you will need to take in order to develop this feature in your custom plugin:

magento-mass-action

1. Prepare a Grid Container and Grid in your backend:
For this you will need a collection of records, a controller, and the basic blocks of a grid admin page. I will not cover this in this post, but you can find more about setting it up nicely on Tips for Twits Magento Blog, the article is called Howto: Repackageable custom extension development in Magento.

2. Add the _prepareMassaction() method inside the Grid class:
Add the following code inside your module class that extends Mage_Adminhtml_Block_Widget_Grid:

protected function _prepareMassaction()
 {
 $this->setMassactionIdField('entity_id');
 $this->getMassactionBlock()->setFormFieldName('product');

 $this->getMassactionBlock()->addItem('add', array(
 'label'    => Mage::helper('rma')->__('Add Products to RMA List'),
 'url'      => $this->getUrl('*/*/massAdd'),
 ));

 return $this;
 }

A few things to notice:

2.1. ‘entity_id’ is the database column that serves as the unique identifier throughout your data structure, including: db table, single product magento model, and the collection.
2.2. setFormFieldName(‘product’) – the text ‘product’ is flexible but you will need it in the next step, so remember it.
2.3. The routing string ‘*/*/massAdd’ will triger a method called massAddAction() in your controller.

3. Prepare the actual action to be taken in your controller
Here is the code that needs to be added, notes are below:

public function massAddAction()
 {
 $productIds = $this->getRequest()->getParam('product');
 if(!is_array($productIds)) {
 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('rma')->__('Please select product(s)'));
 } else {
 try {
 $product = Mage::getModel('catalog/product');

 foreach ($productIds as $productId) 
 {
 $product->reset()->load($productId);
 $rmaProduct = Mage::getModel('rma/product');
 $rmaProduct->setName($product->getName())
 ->setDescription($product->getDescription())
 ->setStatus(Activo_RMA_Model_Product::STATUS_ENABLED)
 ->setCreatedAt(now())
 ->setCatalogProductId($productId)
 ->save();
 }
 Mage::getSingleton('adminhtml/session')->addSuccess(
 Mage::helper('rma')->__(
 'Total of %d product(s) were successfully added to the RMA product list', count($productIds)
 )
 );
 } catch (Exception $e) {
 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
 }
 }

 $this->_redirect('*/*/index');

 }

Notes:

3.1. The method name is routed from the previously provided $this->getUrl(‘*/*/massAdd’) method.
3.2. Yes, the variable $productIds contains a simple array of entity_id numbers. This is not a collection by any means, so you should treat it this way.
3.3. Inside the main foreach loop, you can pretty much do whatever action you wanted.

In conclusion, with about 20 lines of code and updates to two files we are able to leverage a powerful built in feature provided by Magento which allows for mass actions on our records. Obviously, this little excerpt is not for the beginners out there. However, I hope this will make some developers’ lives a bit easier.

Let me know how what other advanced Magento features you use the most.

Magento , ,

Magento’s Order Management Workflow: Comprehensive but Unrealistic #2

September 29th, 2009

Yes, I finished the goEmerchant payment plugin for Magento and figured out how to use and modify Magento’s Order Management Workflow. It did require a lot of reverse engineering and a bit of tweaking of the button labels to improve the admin’s understanding on what each operation actually does.

Magento's Order Management Workflow is like a plumbing job, maybe not so bad.

Pre-Authorize transaction on Checkout:
So, the first thing we want to do is pre-authorize transactions when a user places an online order and checks out from Magento. That is relatively easy and mostly built in. Nothing needed to change from a workflow point of view. The only thing we had to realize is that there are two values that stay with the payment which is associated with the Order and we can use for the goEmerchant reference_number. Those are: ‘cc_trans_id’ and ‘last_trans_id’ – I chose to use ‘cc_trans_id’ just because it made more sense.

Cenceling & Voiding an Order:
In Magento you can only void invoices. However, if you create an invoice you in effect will triger the captur() method of the payment. Now, goEmerchant allows you to void only unsettled transactions – so we had to handle the voiding before we create an invoice. Luckily Magento has the cancel() method that is called when an order is canceled. So, we wired the void operation to the cancel() method and relabeled the button from ‘Cancel’ to ‘Cancel & Void’ – to explain what it actually does. We also turned off voiding, since there is not much sense in voiding an already created/settled invoice.

Settling a Transaction (Capture Funds):
goEmerchant needs the eCommerce application to send a ‘settle’ request when the order was processed, shipped, and invoiced. This request than places the transaction in the settled queue and will be processed usually at 2am. This was relatively easy and no modifications to the workflow needed here. All we needed to do is perform the ‘settle’ request in the capture() method of the payment. Note: since our module still allows Authorization & Capture setups, we had to handle the special cases here. But overall no problem.

Refund or Creditmemos:
Magento has this option to create new credit memos, these serve as what we call it as refunds. Luckily, here Magento’s Order Management Workflow works finde and allows you to process a credit memo and ‘Refund Online’. It is actualy labeled ‘Refund’ and the other option is to ‘Refund Offline’. So, in our plugin we are simply wiring the refund request in the refund() method of the payment. Note: Magento also allows a refund of the entire order which is not triggering anything. So, we will need to be cautious to explain to our merchants that they will need to refund already created invoices.

Conclusion
Magento’s Order Workflow is definitely rich in features and allows great level of flexibility for the merchants. However, some of it would not make sense and seems like overly complex for something that should be configurable but simple. We were able to get our plugin working the way we needed it to by a combination of using the existing functionality and relabeling some buttons. We will also need to caution our merchants from certain actions or make the decision to remove these options altogether.

If you are interested in our goEmerchant payment module for Magento, email us at info@activoinc.com or call at (888) 897-7775.

Magento ,

The Case for ZenCart: Supporting the Long Tail of eCommerce

June 18th, 2009

While Zen-Cart is one of the best open source ecommerce platforms it has plenty of deficiencies, however I recently understood that it will always be able to keep its niche and therefore always have a market.  Of-course this will remain the case as long as its leaders remain true to its spirit.

the_long_tail_of_open_source_ecommerce_platforms

Zen-Cart is an unwilling offspring of the popular osCommerce. Like all offsprings, it is an improved version of its predecessor with better templating system, class oriented design, and notification systems but still maintains its characteristics of spaghetti code and somewhat convoluted and non-flexible checkout process.

Zen-Cart’s strengths are its simplicity which gives many non-programmers the opportunity to tweak and add (or remove) features to their likings with no major effort. This means that implementing a Zen-Cart ecommerce website is usually inexpensive and fast. Another great benefit of the system’s simplicity is speed. Zen-Cart is many times lighter than many other ecommerce systems even without complex caching technologies. Together, these benefits support a specific market: the market of light ecommerce. I am talking about online shops with 1 to 100 daily transactions or even less. It can obviously support more than that but the simplicity and the light weight features will attract the small business which is budget oriented.

The light ecommerce market while being small in terms of overall sales figures is relatively large and will get larger and larger with time. This is also known as the long tail of any market, in our case it is the long tail of the ecommerce market. This means that the numbers of installations will most likely be large and not insignificant. It also means that it is a valid market and will not vanish overnight with any other solution such as Magento who now charges a hefty amount for licensing its Enterprise version.

Before you rush to declare this light and feature packed ecommerce platform the kind of the long tail ecommerce market, don’t underestimate the challenges that it is facing. With over a year and a half of no significant updates its market share is shrinking fast. The default template and the admin panel need some serious reworkings to get up to par in UI and design with other open source challengers and a major cleanup and reorganization of the backend configurations is way overdue. While it supports XHTML and validates correctly, the default template needs to be reworked without the tables.

In any case, Zen-Cart still serves its purpose as a free and light open source ecommerce platform. And here at Activo we have recently developed a Recurring Orders payment module that comply with PCI requirements and integrates well into the ARB module of Authorize.net. I’ll soon post links to an initial free version, a commercially licensed version should be available in about a month or so.

What do you think of ZenCart? here to stay or yet another open source project that will be lost in oblivion? somewhere in the middle perhaps?

eCommerce, Magento, Web Development, ZenCart , , ,

Open Source eCommerce: the Good, the Bad, and the Ugly!

January 28th, 2009
Comments Off

A few days ago I read Karry Watson’s article titled Open Source E-Commerce: Twelve Promising Programs. Karry provides a good overview of the current state of open source eCommerce options for online vendors. From our experience with many different vendors and from recent trends I wanted to discuss three open source ecommerce systems from Karry’s list that power most of the shopping carts out there, now and in the near future. Ugly first:

The Ugly: osCommerce

There is no hiding for this huge collection of 3 line scripts that somehow compose a shopping cart. I think any web developer that took a few classes of computer science knows that it is a big hack not a piece of software. Any additional functionality needs to be glued somehow and made work. Oh, by the way – good luck trying to use two extensions at the same time. Anyway, you see where I am going with this. Easy to setup, easy to use, not programmed well, hell to maintain, nightmaire to develop. Ugly.

The Bad: Zen-Cart

I personally fell in love with this shopping cart back in 2004 very close to the split from osCommerce. What a great energy this project had. The sky was the limit. Someone recently pointed out that open source fatigue happens to many projects: starts great, reaches pubirty, and starts lingering. Great codgin techniques, not complete by any means but every release converts more code into clean, object oriented, design pattern oriented beauty. Unfortunately, recently development has stalled. Ok, it didn’t, the developers are saying that they are very close to the next release which got extended (and additional features got added). Bottom line, no releases in 2008 at all. Meantime, where is our improved admin interface? Web 2.0 features? quantities by attributes? Bad.

The Good: Magento Commerce

Still new and growing fast. The new kid on the block. What I like about Magento is the solid foundation which is based on the Zend Framework. In a way, forcing good development practices: MVC, templating, scalability, layering, etc. Magento is here to stay, moreover, it will quetly revolutionize the open source ecommerce space and force all the players to push the envelop. This includes all the small size commercial shopping carts ($1-$2,000 per license). Good. Great!

What are you using? What are you going to use?

eCommerce, Magento, Web Development, ZenCart , , , ,

A list of CMS and eCommerce systems that officially support jQuery

December 7th, 2008

Last updated: December 7th, 2008.

Recently, jQuery – the agile JavaScript Library – has reached a tipping point. Here is a list of CMS and eCommerce systems that our clients are most interested in and their status with regard to jQuery.

Systems where jQuery is officially supported:

1. Microsoft has adopted jQuery and will offer intellisense support in its dominant IDE: Visual Studio 2008.

2. Umbraco - an open source CMS now offers jQuery by default and using jQueryin Umbraco is a matter of adding a simple call in order to include the jQuery files in the page.

3. Drupal - is an open source CMS and Framework CMS, as of version 5 it offers jQuery streight from its core. There are plans to build a centralized jQuery plugin in Drupal version 7.

4. Typo3 - is an open source CMS Framework. Typo3 has a jQuery extension that allows advanced integration with jQuery.

5. DotNetNuke - an open source ASP.NET CMS. Since October 2008 DotNetNuke offers built in jQuery support beginning with version 5.

Systems where jQuery is not supported:

1. Joomla - seems to favor Mootools over jQuery. Here is an article on how to support jQuery within Joomla and avoid conflicts with other libraries.

2. Zend Framework – the leading PHP Framework following the MVC design pattern. A press release was issued in May 2008 announcing Zend Framework and Dojo partnership.

3. Magento Commerce – an open source eCommerce platform that is gaining huge market share in the eCommerce industry. Currently Magento Commerce supports prototype JS library instead of jQuery, but offers ways to integrate jQuery easily.

4. Zen-Cart - an open source eCommerce (competing with Magento). At the moment Zen-Cart is not supporting any JavaScript library in its core.

Other systems and their relationship to jQuery:

1. WordPress - an open source blogging software. Uses jQuery for its core functionality and is avilable for any third party plugin.

2. Ektron CMS400 – Ektron has an enterprise level CMS with advanced content editing features. Oddly enough, Ektron seems to have embedded their own version of jQuery in their code.

While jQuery seems to be favored the favored JavaScript library by many developers, it has yet to be declared as the default one for many projects and systems. I’ll be keeping this list updated in the following months. Let me know if there is a system that interests you and I did not list it here.

Content Management Systems, eCommerce, Ektron, Joomla, Magento, Web Development, ZenCart , , , , , , , , , , , , , , , ,

Can Magento and Typo3 be integrated? Yes, with TypoGento

December 4th, 2008
Comments Off

Magento is now able to connect to Typo3. The connector is called TypoGento. At the moment it is only version 0.1.0 and the demo did not show any sign of integration. But, if you ever wanted the best in ecommerce and the best CMS framework that are both open source and free – you got it.

Now, I also heard that Magento and Joomla will be integrated pretty soon. Any idea when?

Content Management Systems, eCommerce, Joomla, Magento , , ,

Is Magento Commerce the new Joomla?

October 29th, 2008

If you are in the open source eCommerce industry, you probably heard about the new kid around the block: Magento Commerce. If you follow the industry news, you know that since its announcement back in April of 2007, Magento’s popularity is nothing shy of sky rocketing. Certainly feels like mid-2005 with the emergence of Joomla and the demise of Mambo in the CMS space. So, what makes this open source ecommerce platform so popular? What is it still lacking, but seem unimportant? First, we can clearly see an obvious trend: the emergence of Magento and the decline of both Zen Cart and osCommerce:

Search trends for the terms Zen Cart, osCommerce, and Magento

Search trends for the terms Zen Cart, osCommerce, and Magento

The notion of ecommerce built from the ground up with today’s modern tools gives shopping cart owners a warm  fuzzy feeling. Top it with the fact that the modern tools are solid MVC (Model View Controller) design pattern and the Zend Framework and you get a bunch of online stores that are ready to jump on this promising bandwagon. Ok, I am missing one important fact! These days, admit it or not, looks and coolness are gold. Not surprisingly, this is were Magento shines!

But wait a minute, is Magento Commerce ready for prime time? Well, this is where you see a divide in the industry, this is where the chasm and the bell curve comes in. Yes, Magento does lack performance, stability, scalability, and some trivial features that existed for many years in other carts like Zen Cart and osCommerce. But the trend is obvious and there is no going back. If history repeats itself Magento will become a leader very very soon!

Viva la competicion!

eCommerce, Magento, Web Development, ZenCart , , , , ,

ZenCart and Magento for eCommerce

September 22nd, 2008

Anyone who is involved with an online shopping cart and was considering open source solutions probably stumbled upon two major ecommerce providers: ZenCart and Magento Commerce. ZenCart is an evolving and older shopping cart with roots in osCommerce, while Magento Commerce is a newcomer to this category written from scratch on top of the new Zend Framework. Since we support both platforms, we often are asked to provide a basic comparison analysis for the business owners and this is what I will try to do in this article.

ZenCart

This is a great open source shopping cart that can power almost any size eCommerce sites. We have successfully used ZenCart for sites offering 20 products all the way up to tens of thausands of products and variations (which by the way is connected to a POS and kept up to date to the minute). Since its fork from osCommerce ZenCart has gone through extensive development and now offers much broader extendability and robust template system. Some of the underlying systems that make this shopping cart so robust are: template system, initialization system, object autoloaders, plugins a-la observer design patern, flexible and extendible configuration system, and more.

One of the biggest disadvantages for ZenCart is that all these great systems were built on top and in an after thought to an existing platform. Hence, there are many dependencies and the learning curve for professional grade customization and development is steep. For example, one of the tasks that current core developers are working on is to transform additional funcitons to object oriented design, in other words, they are still trying to get rid of the spagheti code left from the osCommerce days.

Nevertheless, ZenCart is a true workhorse that has proven itself many times and with hundreads of thausands of stores world wide. In fact, it has excellent support for multiple languages and multiple currencies stores.

At Activo, Inc. we have developed many modules to enhance various aspects of the store: front end, specialized templates, taxes by zipcode, easy search suggestion tool, even a real QuickBooks integration module and a real time Point of Sale (POS) integration with RunIt systems.

One more thing that ZenCart excels in when the right modules and the right setup is applied is SEO (Search Engine Optimization). Once setup correctly, ZenCart is one of the most SEO friendly stores out there. I have seen multiple times where a brand new ZenCart store with some SEO efforts generating more than $50,000 per month in sales (within 2-3 months of Go-Live).

ZenCart bottom line: Great solution if you want to see a solid and proven shopping cart with mostly standard features and you do not care about the type of technology that powers it. Currently, for best and fastest deployment ZenCart is second to none.

Magento

Magento is a brand new (about a year old as of writing this article) and it is now beginning to see community and developer adoption. Magento is written on top of PHP5 and Zend Framework. A bit about the framework: the new Zend Framework is sponsored by industry leaders such as IBM and Zend and is largely based on the MVC design patern. In a way, it is the answer to the .NET framework in the PHP world. There are similar frameworks and they may even be older and more mature, like Symphony or CakePHP. However, since the Zend Framework is backed by both IBM and Zend it is very likely that this framework will become the industry standard.

Magento was developed from scratch and in an object oriented manner on top of the new Zend Framework. Therefore, it is expected to have better extendibility options for developers and much better module/plugin management consules in the back-end however will probably come at the expense of instability in the short term. Magento’s templates out of the box look sharp and eye candy. Its creator definitely placed an emphasis on the way it’s admin panel feels & looks and the way its demo templates look & feel. Additionally, almost all aspects of the UI feels a lot more like Web 2.0 with many AJAX features and many time saving UI features.

One of the biggest downsides to Magento is its current speed since it lacks an effort in optimizing its DB and overall structure. Hence, it is relatively heavy and requires a bit of advanced know-how when installing and setting it up. It’s forums seem to be gaining traction with developers and many developers say that once you migrate a store to Magento you will never look back.

Magento bottom line: While it is definitely a matter of time until we see the real value, Magento does seem to have some advantages over any other open source eCommerce system. Merely the fact that it was developed from scratch recently means that a whole lot of best practices are thought of right of the bat instead of showing as an after thought (which we as developers have to deal with it). Nevertheless, Magento’s forums indicate that the product has yet to have reached maturity. If you are ok with somewhat unstable solution and looking for the absolute cutting edge shopping cart Magento is for you!

eCommerce, Magento, PHP/MySQL, Web Development, ZenCart , , , , , , , , , , ,

Looking Ahead: ZenCart ver 1.4

August 25th, 2008

The ZenCart developer team seems to be hard at work and preparing to deliver a new version of ZenCart: ver 1.4. The core developers posted a roadmap brief for version 1.4 back in September of 2007. Recently, additional entries have been posted in the forums describing in more detail the upcoming changes and signaling a new release is to be expected soon.

The currently described updates to ZenCart are done all around the DB, its architecture, and improving its performance. To summarise from the ZenCart forums:

New Database Driver Layer
Extremely light/flexible drivers make it easier to support other Database Types
Preliminary support for innodb and mysql transactions

Sql Caching system rewritten
Much easier to add new caching types
Preliminary Support for Memcache

Use of MPTT for category structure
Reduces number of queries needed to ‘describe’ the category structure
Improves user experience thru reduced page load times

Supporting Classes to reduce query load
Hugely reduces queries needed
Reuses queries using Cache to further improve performance

The roadmap for ZenCart ver 1.4 promises the following updates to the code (summarized):

  • Better usage of PHP 5.2 features. This also means 5.2 will be the new minimum requirement.
  • More Object Oriented code, less of the old osCommerce code.
  • Lots of DB improvements (some is described above, seems more is yet to come).
  • Category structure converted to MPTT format. MPTT stands for Modified Preorder Tree Traversal (explanation of MPTT).
  • Performance improvements for sites with lots of product attributes.
  • More function libraries converted to classes.
  • Duplicate components shared between admin and catalog.
  • Template system enhancements: less tables and more admin control.
  • Additional notifiers for the observer system.
  • Transaction support with InnoDB. Also mentioned as initial stage according to the recent posts of the updates that were done so far.
  • SwiftMailer instead of phpMailer.
  • Stock and SKU per product attribute.
  • Security enhancements.

Keep up the good work!

eCommerce, PHP/MySQL, Web Development, ZenCart , , , , , , , ,