Magento themes and extensions

Magento: Add Instructions to Form Field in Admin Product Add/Edit

Share
Posted on May 30th, 2011 | Posted by admin

I made some custom functionality that can happen with a product’s Short Description. Depending on what is put in that textarea, icons and special product-specific links can be displayed on that product’s view page. It requires a specific format though for it to work – and instead of emailing the client and having them forget how to do it correctly, it would make more sense to put instructions next to the Short Description field in the Admin product add/edit page.

For this example, we’ll be adding instructions to the Short Description. If you take a look at the source code, you’ll see that the short description is displayed with this code:

1
2
3
4
5
6
<tr>
    <td><label for="short_description">Short Description <span>*</span></label></td>
    <td><textarea id="short_description" name="product[short_description]" type="textarea" ></textarea></td>
    <td></td>
    <td><small></small></td>
</tr>

Magento: Add Custom Module For Custom Admin Config Options

Share
Posted on May 30th, 2011 | Posted by admin

In my previous post, I showed you how to add instructions to the Short Description on the product add/edit form. While this is useful, if you ever wanted to change the instructions, you would have to open the template file and edit it manually. Wouldn’t it be nice to edit those instructions right in the admin configuration options? Yes, it would!

It’s quite simple to do – and it should only take you a few minutes to implement this. But, the options are endless. You can add all sorts of custom configurable options that you can edit in the admin panel very easily.

To get started, you’ll want to create a new module XML file similar to this: /app/etc/modules/MyMods_All.xml. Put the following code in that file:

Creating cron script in Magento

Share
Posted on May 27th, 2011 | Posted by admin

Creating Magento cron script is very simple thing. First of all we have to create the module, (I hope that you know how to create magento module) and add in config.xml file next code:

1
2
3
4
5
6
7
8
<crontab>
<jobs>
<inchoo_birthday_send>
<schedule><cron_expr>0 1 * * *</cron_expr></schedule>
<run><model>birthday/observer::sendBirthayEmail</model></run>
</inchoo_birthday_send>
</jobs>
</crontab>

Next step, we have to create model file observer.php (in folder model) with method sendBirthayEmail

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Inchoo_Birthday_Model_Observer
{
public function sendBirthayEmail()
{
//this collection get all users which have birthday on today
$customer = Mage::getModel("customer/customer")->getCollection();
$customer->addFieldToFilter('dob', array('like' => '%'.date("m").'-'.date("d").' 00:00:00'));
$customer->addNameToSelect();
$items = $customer->getItems();
foreach($items as $item)
{
// send email or do something
}
return $this;
}
}

This cron will be executed every day at 01:00 AM. The important thing: You have to set cron execution on the server (www.yourstore.com/cron.php), without it will not work.

Source:  http://inchoo.net/ecommerce/magento/creating-cron-script-in-magento/

How to create a new product type in Magento

Share
Posted on May 27th, 2011 | Posted by admin

Magento comes packed with several product types: simple, grouped, configurable, virtual, bundle, downloadable. Sometimes clients request can reach beyond any of these built in product types functionality. In such cases, usual way of handling things is throwing some new attributes and hooking into some events from which you can handle and “re-route” certain logic.

In some cases, the required product logic can extend to such level that you are better of with building a new product type in Magento. Why, you might ask? Becase of the more finer control you can achieve on product trough your own models than to poke around on the existing stuff.

Attached to this article is a fully working extension I wrote that creates a new product type in your Magento store. This new product type uses code name “customproduct”. Its based on the Mage_Catalog_Model_Product_Type_Abstract class, the one on which the “simple” product is build upon. Unlike “simple” product type, this “customproduct” does not have any, whatsoever, additional logic built in. This, I leave to you.

Also, extension comes with several “hooks” to certain Magento controllers actions. If you open the app/code/local/Ajzele/CustomProduct/Model/Observer.php you will see implemented several “blank” methods as hooks. Going to config.xml file of this extension will show you what these methods “observe”.

Magento: Get Bundled Items By Bundle Product

Share
Posted on May 26th, 2011 | Posted by admin

This post is just a small snippet that will help you to get all products that are used do construct any bundle product.

Of course, I’m not sure how useful can it be as is, so if you need optimized version of it, you will need to play with it for a while.

You will need some basic knowledge of PHP language in order to fix formatting issues that you may (not saying that you will) encounter due strange behavior of code display plugin in wordpress.

I tried to find it on google few days ago and I had no luck, so if anybody has better solution, please comment.

Here we go:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
< ?php
$bundled_product = new Mage_Catalog_Model_Product();
$bundled_product->load(YOUR_BUNDLED_PRODUCT_ID);
$selectionCollection = $bundled_product->getTypeInstance(true)->getSelectionsCollection(
$bundled_product->getTypeInstance(true)->getOptionsIds($bundled_product), $bundled_product
);
$bundled_items = array();
foreach($selectionCollection as $option)
{
$bundled_items[] = $option->product_id;
}
print_r($bundled_items);
?>

Source: http://inchoo.net/ecommerce/magento/magento-get-bundled-items-by-bundle-product/

Page 31 of 48« First...1020«2930313233»40...Last »