Create configurable product in Magento programmatically

Following post includes the code that can be used to create a configurable product in Magento.

Brief introduction about configurable product

When adding new products to your Magento store you have the option to select the type of the product. The most basic option is simple product.
That’s just a single item with no specific attributes/options that can be changed by the buyer.
With the configurable product type you can offer an item with some options that can be configured by the customers themselves.
For example, you can sell the same model of shoes that are offered in different colors, sizes, etc. Instead of creating several simple
products for each size of the same shoe model that will be displayed individually on the frontend,
for instance, you can create a configurable product which will allow the customer to select the size before ordering the product.

To understand the code, one must have a basic understanding of how configurable product works in a Magento store.

Continue reading

Create Simple Product in Magento Store Programmatically

 

We are creating a simple product programmatically in Magento Store. There is nothing much to describe in this post.
I am using the basic required information to create the product. May be your store needs more attributes to create the product, but to keep the post simple I am using just 2 custom created attributes.

 

14

 

Following script contains a function that gives the option id of option label for any attribute code.
For example, Magento needs the 321(assume option id for label “Black”) to save the value of attribute color.

Continue reading

Ajax Breadcrumb Helper Class in CakePHP

Helper to create breadcrumbs in view file
Creates ajax links
1. First go to the folder app/View/Helper and create a file name BreadcrumbHelper.php.
2. Place the below code in the BreadcrumbHelper.php

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
< ?php
App::uses('AppHelper', 'View/Helper');
class BreadcrumbHelper extends AppHelper 
{
public $helpers = array('Html','Js' => array('Jquery'));
/*
$links array containing information to create links
'title' => 'Text shown for link'
'url' => url to redirect, can be created by sending the controller and action
'class' => optional, to be added id specific CSS needed
*/
public function create($links)
{
$html = '<div id="path">';
$html .= $this->Js->link($link[0]['title'],$link[0]['url'],
array(
'before' => $this->Js->get('#loading')->effect('fadeIn'), 
// #loading - id to show the gif while content loads
'success' => $this->Js->get('#loading')->effect('fadeOut'),
'update' => '#content', 
// #content - id to update the content on request complete
'class' => $link[0]['class']
)
);
foreach($links as $link)
{
$html .= '<img src="path to image"/>';
// separtor for links, you can also use any symbol, its your application, you are the boss
$html .= $this->Js->link($link[0]['title'],$link[0]['url'],
array(
    'before' => $this->Js->get('#loading')->effect('fadeIn'),
    'success' => $this->Js->get('#loading')->effect('fadeOut'),
    'update' => '#content',
    'class' => $link[0]['class']
)
    );
}
$html .= '</div>';
return $html;
}
}
//3. Add this helper to controller where you want to use..
class TestsController extends AppController
{
var $name = “Tests”;
var $helpers = array('Breadcrumb');
//code specific to your application
}
??
//4. Now, you can use this helper in your view file.
echo $this->Breadcrumb->create(array(
array(
'title' => 'Home',
'url' => array('controller' => 'some_controller','action' => 'some_action'),
'class' => ''
),
array(
'title' => 'Listing Paeg',
'url' => array('controller' => 'some_controller','action' => 'some_action','some_parameters_if_needed'),
'class' => 'current'
),
array(
//more links
)
));
?>

Thats it, you will get beautiful breadcrumbs on your view page wherever you want
That too with fancy ajax loading
You can always use normal links in your helper,if ajax scares you
Note :: Dont forget to write $this->Js->writeBuffer(); in case you are using ajax links

Prevent Direct Url Access in PHP

Add the below piece of code to header file of your application and prevent direct URL access . Any user who tries to navigate via changing the URL or post data will be redirected to previous webpage.

1
2
3
4
< ?php
if(!isset($_SERVER['HTTP_REFERER']))
{     echo '<script>history.back();'   }
?>