Comparison between Opencart And Magento

For last several months i have been working on two most used e commerce frameworks in open source Opencart and Magento

There are lot of comparisons are available between two saying which one is strong and flexible about support and other factors.

I would like to add some thing on this topic too

First I came across opencart framework around year back, at that time I was new to any framework, so started exploring and got  a totally new experience.

within a couple of mins i m ready with default framework options with some sample data a full working admin a nice template and working e commerce site.

After couple of days I showed it to my seniors and they asked me to prepare a demo for diamond trading  site. I have no reference in hand just a basic three page design.

home page category page and details page.

I searched for some content on web for diamond related thing and came up with http://naturaldiamondcompany.com

On this we got couple of more projects to do, and i become familiar with opencart. Such a simple framework, you dont have to do much to explore, and also if u need to change some functionality

the code is open and easy to modify

Few days later for some project the client is specifically asked for magento, another e commerce framework.

I downloaded next day and you dont believe it took around two days to understand the installation process and set up the default functionality

After week too i m struggling to set up the common options like category products reviews shopping cart etc

Its too horrible, another thing what i came across it not accepting localhost as the default host name, you need to provide the local IP address in the config file for admin to work

An explanation given by experts that its for live domain and for localhost

Another huge issue i got with database shifting from local to live, It took me around one hour to check where is damn config file for database

where in opencart its much simple in the main folder for admin and for front end u will get the config file with simple variables

Another issue with magento is bulk upload product say around 50k or 100k or more dynamically via script, It took me around two days to find out the exact database structure where magento insert the data

In couple of forums i got solution to use the magento default controller via Mage.php file and use the insert method with parameter assign and use it in loop

I thought the problem is solved but the script took horrible time to insert the products in bulk. I checked with fewer products it loaded fine but as the count increased the time increased exponentially

For opencart it took around 10 mins to understand the product database and i build the script in less than two hours for the first time and inserted the 100k records in less than two mins.

When it comes to customization of both the framework Opencart community always helped me a lot with quick response where in magento i got suggestions to use paid modules for the same functionality

 

Following image will explain you in detail characteristics of each of them

Comparision between opencart and magento

Comparision between opencart and magento

Magento Add image to media gallery

Following snippet used to add image to magento image gallery via script

The snippet can be used in the previous post used to show how to insert the simple product via script having custom attributes

First you need to create the product object via the product model as follows

require_once 'app/Mage.php';

$product = Mage::getModel('catalog/product');

Now once the object in place then you can add the image as product attribute

$product->addImageToMediaGallery('full/path/to/image', array('small_image','thumbnail','image'), false, false);

Note the second parameter that specifies the where to add the image, currently all three given ie small image thumbnail and large image.

Depending on the image name various images can be added setting individual images

The API reference can be found at

http://docs.magentocommerce.com/Mage_Catalog/Mage_Catalog_Model_Product.html#addImageToMediaGallery

Magento Bulk product delete

When you first look at Magento database, it can be overwhelming because of its complexity. The Magento database is heavily dependent on EAV (Entity Attribute Value) model. While the EAV model makes it easier to expand the database, i.e. adding your own entities or attributes specific for your store, SQL codes can be very difficult to write.

Before you customize Magento database, make sure you read through EAV model and you understand Magento table structure thoroughly.

EAV Core Tables
All EAV tables are prefixed with “eav_”.

  • eav_entity_type: table of all entitiesIt contains information about entity codes, entity models, entity tables and more.
    Example entities: customer, order, catalog_category, catalog_product, invoice, shipment, and so on.
    Each entity has a corresponding data table prefixed with “_entity”, i.e. customer_entity, sales_order_entity, catalog_category_entity, and so on.
  • eav_attribute: table of all attributes
    It defines all necessary attributes for each entity. For example, a customer has first name, last name, email address and so on. Customer is defined as an entity in theeav_entity_type table and customer’s attributes such as first name, last name or email are defined in the eav_attribute table. Hundreds of attributes are defined by default with Magento installation.
  • eav_attribute_option, eav_attribute_option_value
    These two tables are used to define options for each attribute. For example, the manufacturer attribute can have “Toshiba”, “Dell”, or “HP” for its options. These option values are stored in the eav_attribute_option_value table and the relationship of each option and the attribute is stored in the eav_attribute_option table. An option can also have multiple option values when it’s used for multiple stores.
  • eav_attribute_set
    This table is used to define different attribute sets for an entity. For example, a cell phone has different options from a camera. Both cell phone and camera are products (entities) that have different option sets (attribute sets).

Table Sets (Table collections)
In Magento database, an entity can have several tables that share the same prefix. For example, the product entity has the catalog_product_entity table for its main data and several other tables prefixed with “catalog_product_” such as catalog_product_entity_int, catalog_product_entity_media_gallery, catalog_product_entity_text and so on.

To store the data more efficiently, product details are stored separately depending on their data types. When the value of the data is an integer type, it’s saved in the catalog_product_entity_int table, and when its type is an image, it’s saved in the catalog_product_entity_media_gallery table. The whole point is not saving big image data with small integer data in the same table.

Tables to Define Relationships
The catalog_category_product table, catalog_product_website or downloadable_link_purchased are examples of the tables that show relationships. The catalog_category_product table showwhich category includes which products and the downloadable_link_purchased table shows which order has which downloadable links.

Once you understood this then following series of queries will help you to clean your existing product data in fraction of seconds

TRUNCATE TABLE `catalog_product_bundle_option`;
TRUNCATE TABLE `catalog_product_bundle_option_value`;
TRUNCATE TABLE `catalog_product_bundle_selection`;
TRUNCATE TABLE `catalog_product_entity_datetime`;
TRUNCATE TABLE `catalog_product_entity_decimal`;
TRUNCATE TABLE `catalog_product_entity_gallery`;
TRUNCATE TABLE `catalog_product_entity_int`;
TRUNCATE TABLE `catalog_product_entity_media_gallery`;
TRUNCATE TABLE `catalog_product_entity_media_gallery_value`;
TRUNCATE TABLE `catalog_product_entity_text`;
TRUNCATE TABLE `catalog_product_entity_tier_price`;
TRUNCATE TABLE `catalog_product_entity_varchar`;
TRUNCATE TABLE `catalog_product_link`;
TRUNCATE TABLE `catalog_product_link_attribute`;
TRUNCATE TABLE `catalog_product_link_attribute_decimal`;
TRUNCATE TABLE `catalog_product_link_attribute_int`;
TRUNCATE TABLE `catalog_product_link_attribute_varchar`;
TRUNCATE TABLE `catalog_product_link_type`;
TRUNCATE TABLE `catalog_product_option`;
TRUNCATE TABLE `catalog_product_option_price`;
TRUNCATE TABLE `catalog_product_option_title`;
TRUNCATE TABLE `catalog_product_option_type_price`;
TRUNCATE TABLE `catalog_product_option_type_title`;
TRUNCATE TABLE `catalog_product_option_type_value`;
TRUNCATE TABLE `catalog_product_super_attribute`;
TRUNCATE TABLE `catalog_product_super_attribute_label`;
TRUNCATE TABLE `catalog_product_super_attribute_pricing`;
TRUNCATE TABLE `catalog_product_super_link`;
TRUNCATE TABLE `catalog_product_enabled_index`;
TRUNCATE TABLE `catalog_product_website`;
TRUNCATE TABLE `catalog_product_entity`;

TRUNCATE TABLE `cataloginventory_stock`;
TRUNCATE TABLE `cataloginventory_stock_item`;
TRUNCATE TABLE `cataloginventory_stock_status`;

INSERT  INTO `catalog_product_link_type`(`link_type_id`,`code`) VALUES (1,'relation'),(2,'bundle'),(3,'super'),(4,'up_sell'),(5,'cross_sell');
INSERT  INTO `catalog_product_link_attribute`(`product_link_attribute_id`,`link_type_id`,`product_link_attribute_code`,`data_type`) VALUES (1,2,'qty','decimal'),(2,1,'position','int'),(3,4,'position','int'),(4,5,'position','int'),(6,1,'qty','decimal'),(7,3,'position','int'),(8,3,'qty','decimal');
INSERT  INTO `cataloginventory_stock`(`stock_id`,`stock_name`) VALUES (1,'Default');

But Make Sure you backup your data first If anything goes wrong in between then you should be prepared. 🙂

Magento : Display Products by Attribute set name

While writing the custom module I came across a situation where in there is need to display the custom products that is under specific attribute set, while searching on google I found lot many code snippets but following works for me

//Fetch attribute set id by attribute set name
$attrSetName = 'Diamonds';
$attributeSetId = Mage::getModel('eav/entity_attribute_set')
	->load($attrSetName, 'attribute_set_name')
	->getAttributeSetId();

//Load product model collecttion filtered by attribute set id
$products = Mage::getModel('catalog/product')
	->getCollection()
	->addAttributeToSelect(array('name')) // Here need to define the array of attributes to fetch, 
                                               //currently only name is fetched
	->addFieldToFilter('attribute_set_id', $attributeSetId);

//process your product collection as per your bussiness logic
$productsName = array();
foreach($products as $p){
	$productsName[] = $p->getData('name');
}
//return all products name with attribute set 'my_custom_attribute'

		Mage::register('data', $productsName);

To understand the above code you need the basic knowledge of magento framework for module development

Will write in detail about basics of module development in another series

Magento Add product via script

Magento allows several different ways to add products to the catalog, including manual editing, upload via spreadsheet and the web services Magento Core API. For developers who want to add products through PHP however, there are a few caveats to be aware of for the product to be displayed on the frontend.

The basics of adding a new product are trivial – you get a new copy of the appropriate model, fill in the details and call the save() method:

$product = Mage::getModel('catalog/product');

$product->setSku("ABC123");
$product->setName("Type 7 Widget");
$product->setDescription("This widget will give you years of trouble-free widgeting.");
$product->setShortDescription("High-end widget.");
$product->setPrice(70.50);
$product->setTypeId('simple');
$product->setAttributeSetId(9); // need to look this up
$product->setCategoryIds("20,24"); // need to look these up
$product->setWeight(1.0);
$product->setTaxClassId(2); // taxable goods
$product->setVisibility(4); // catalog, search
$product->setStatus(1); // enabled

// assign product to the default website
$product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId()));

$product->save();

The example above shows a minimal set of attributes you should be setting on a new product. If you run this code and look under Manage Products on the backend, you should see your new product. However, the real trick is making sure they appear on the frontend.

The product should now be appearing on the frontend, but it will probably be showing up as ‘Out of stock’. A product’s inventory and stock options are contained in a separate object, rather than as part of the product itself. Adding the following code somewhere between the getModel() and save() lines will allow you to set the stock data:

$stockData = $product->getStockData();
$stockData['qty'] = 10;
$stockData['is_in_stock'] = 1;
$stockData['manage_stock'] = 1;
$stockData['use_config_manage_stock'] = 0;
$product->setStockData($stockData);

This code gets the product’s stock and inventory options as an array, modifies them and then saves the array back to the object. The options should be self-explanatory – the important one is ‘is_in_stock’, which controls whether the product is in stock or not. The example above sets the product’s ‘Manage Stock’ attribute to ‘Yes’ and un-ticks the corresponding ‘Use Config Settings’ checkbox, so the product will always track stock regardless of the global config setting. This is just an example, so be sure to set values appropriately for your store.