Tag Archives: product

Adding simple Tweet this for Magento products

Featured Image

There are few different ways one can achieve this kind of functionality. Normally in Magento you would do it like a real, “independent”, module (extension) thus loosing at least two ours to make a few lines of code work. Read more

10

Programatically (manually) creating simple Magento product

Programatically (manually) creating simple Magento product

Here is a working sample of code for programatically (manually) creating simple Magento product from within your custom code.

<?php

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

// Build the product
$product->setSku('some-sku-value-here');
$product->setAttributeSetId('some_int_value_of_some_attribute');
$product->setTypeId('simple');
$product->setName('Some cool product name');
$product->setCategoryIds(array(7)); # some cat id's, my is 7
$product->setWebsiteIDs(array(1)); # Website id, my is 1 (default frontend)
$product->setDescription('Full description here');
$product->setShortDescription('Short description here');
$product->setPrice(39.99); # Set some price    

# Custom created and assigned attributes
$product->setHeight('my_custom_attribute1_val');
$product->setWidth('my_custom_attribute2_val');
$product->setDepth('my_custom_attribute3_val');
$product->setType('my_custom_attribute4_val');

//Default Magento attribute
$product->setWeight(4.0000);

$product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
$product->setStatus(1);
$product->setTaxClassId(0); # My default tax class
$product->setStockData(array(
    'is_in_stock' => 1,
	'qty' => 99999
));

$product->setCreatedAt(strtotime('now'));

try {
	$product->save();
}
catch (Exception $ex) {
	//Handle the error
}

?>

Although the process seems pretty straight forward, keep an eye on setStockData method. I was getting some foreign key constraint errors when trying to create instance of stock item then save it into the product object. The above code should handle it quite nicely. Tested on latest Magento version, which is 1.3.2.3 as of time of this writing.

10

How to delete Magento product from frontend template code (from view files)

How to delete Magento product from frontend template code (from view files)

If for some reason (like mine) you need to delete the product from the custom code you placed in lets say view files you might get a bit surprised by the “Cannot complete this operation from non-admin area.” error. Here is a little trick on how to pass behind this. Read more

1

Magento product image switcher

Featured Image

I just wrote small javascript animation example for product images and thought someone may find it useful. It’s a fast way to replace default zoom functionality for the ones that don’t like it.

Read more

42

User friendly product availability message in Magento

User friendly product availability message in Magento

Here is a little something to use on template/catalog/product/view.phtml page. I got few inquiries on how to get the “in_stock” status of a product. Here is a working sample code that shows different messages when and if the product is in stock or out of stock. Read more

0

Kapitol Reef :: Magento store with 1 product

Featured Image

Can an online store have only one product? Sure it can and we give you the one that just launched. Kapitol Reef was founded to develop, perfect, manufacture and market a new breed of snorkels based upon pressure-balanced breathing in the aquatic environment. The entire focus for this company is to deliver best-of-class products, starting with the snorkel. Kapitol Reef is in the market for many years and this week they published a new site. Similar to our work on Teraflex project, we used WordPress and Magento platforms for the development.

Read more

7

Magento product view page analysis (available in PDF)

Featured Image

One of the most edited file in Magento is the template file View.phtml file. Reason for this is that a lot of clients would like to rearrange it differently on their online stores. Here is the analysis of that file and the list of all the methods it uses. Read more

8

Retrieving product information in Magento

Retrieving product information in Magento

If you are developing Magento template sooner or later you will need to obtain some product information and rearrange it to fit your template. One of the most useful function while working with Magento is Mage::getModel($modelClass).

Here is how you would use it to retrieve Magento product information Mage::getModel(‘catalog/product’);.

This ‘catalog/product’ relates to app/code/core/Mage/Catalog/Model/Product.php file. If you open that file you will see it’s actually a class named Mage_Catalog_Model_Product. That same class is extending the Mage_Catalog_Model_Abstract class meaning it inherits all of it’s methods. Read more

0

Create a Color Switcher in Magento

Featured Image

Magento comes packed with a lot of options. But no matter how many options you put into some product you can never cover all of them. One of such options (for now) is a color switcher in Magento. To be more precise, an image switcher based on color selection.

Recently I’ve made a screencast on my site on this subject, with somewhat different title. The idea is to have a dropdown box from which you choose a color and based on the color selection product image changes. All of this is to be based on some simple javascript (in my case, jQuery). Read more

59

Related products, Up-sells, Cross-sells in Magento

Featured Image

There are three types of product relations in Magento: Up-sells, Related Products, and Cross-sell Products.  When viewing a product, Upsells for this product are items that your customers would ideally buy instead of the product they’re viewing.  They might be better quality, produce a higher profit margin, be more popular, etc. These appear on the product info page. Related products appear in the product info page as well, in the right column. Related products are meant to be purchased in addition to the item the customer is viewing. Finally, Cross-sell items appear in the shopping cart.  When a customer navigates to the shopping cart (this can happen automatically after adding a product, or not), the cross-sells block displays a selection of items marked as cross-sells to the items already in the cart.  They’re a bit like impulse buys – like magazines and candy at the cash registers in grocery stores.

Read more

11