Magento Web Development: Upload Product From Front-End To Different Stores

Magento, as all we know, is a large and powerful open-source eCommerce platform. It is mainly based on MySQL relational database management system and written in PHP scripting language on Zend framework. It applies the conventions of object-oriented programming and model-view-controller architecture. There are lots of reasons why Magento web development is the best option for an eCommerce website. It gives you a cool product ordering system.

Magento web development allows you to edit, create, view, and fulfill orders from the admin interface. It provides built-in SEO functionality, tags, descriptions, very clean URLs, site navigation and clean HTML. It offers a number of extra features like the ability to import huge spreadsheets of product, newsletter, built-in functionality for all major merchant accounts with no limits on the number of product or purchases.
Also Read: Backup Buddy: The Best Backup Plugin For WordPress
Magento has its own extensions marketplace called Magento Connect. On Connect, people can download new extensions to their stores by selecting an extension key and adding it to the Connect Manager in their store. It provides regular updates and constant improvements are what you can expect from the Magento team that consists over 200 people working on the CMS on a daily basis.
Ecommerce Magento Web Development
Magento also provides a feature called Multiple Stores. Multiple Stores functionality allows you to power any number of stores or websites within a single Magento installation. This way you can make your site multilingual too. Sometimes you can face problems regarding uploading products in multi stores. It is quite easy through Magento backend but it sometimes gets very tough from a simple front view. Today I am going to show you how you can add products through a spreadsheet with all its data with product images for multiple stores using Magento development.
Codes:
Sample code:
1
2
3
4
5
$insertId=Mage::getSingleton(‘core/resource’)->getConnection(‘core_read’)->fetchOne(‘SELECT last_insert_id()’); // last inserted product id stored here.

$product = Mage::getModel(‘catalog/product’)->load($insertId);

$product->setStoreId(STORE_ID)->setName(‘new_name’)->save();//storing data in this way
Full code:
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
foreach( $xlsx->rows() as $k => $r) {

if ($k == 0) continue;//Ingnoring first column of excel file

try{

//grabbing categories for en

$key=array_search($r[55],$cat_arr);

$key2=array_search($r[56],$cat_arr);

$key3=array_search($r[57],$cat_arr);

 

//grabbing categories for de

$keyde=array_search($r[52],$cat_arr);

$key2de=array_search($r[53],$cat_arr);

$key3de=array_search($r[54],$cat_arr);

 

//grabbing categories for nl

$keynl=array_search($r[49],$cat_arr);

$key2nl=array_search($r[50],$cat_arr);

$key3nl=array_search($r[51],$cat_arr);

 

//Set the path of image folder

$imgpath_total=Mage::getBaseDir().“mediaproimg/12001.jpg”;//.$r[59]

 

 

$newProduct = new Mage_Catalog_Model_Product();

$newProduct->setAttributeSetId(4)

->setTypeId(‘simple’)

->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)

->setTaxClassId(2)

->setCreatedAt(strtotime(‘now’))

->setSku($r[39])

->setWeight($r[40])

->setBrand($r[5])

->setTags($r[58])

->setAlc_percentage($r[42])

->setWeight(’10’)

->setEan($r[37])

->setStatus(1)

->setPrice($r[22])

->setWebsiteIds(array(1))

->setStockData(array(‘is_in_stock’ => 1, ‘qty’ => 99999 ))

->setSetupFee(522)

//->addImageToMediaGallery($imgpath_total,array(‘image’,’small_image’,’thumbnail’),false,false)

->setsetupCost(100)

->setName($r[17])

->setTitle_long($r[18])

->setGoogle($r[64])

->setDescription($r[20])

->setShort_description($r[19])

->setCategoryIds(array(2,$key,$key2,$key3));

 

$newProduct->save();

$insertId= Mage::getSingleton(‘core/resource’)->getConnection(‘core_read’)->fetchOne(‘SELECT last_insert_id()’);

 

$product = Mage::getModel(‘catalog/product’)->load($insertId);

 

#################Dutch###############

$product->setStoreId(7)

->setName($r[12])

->setTitle_long($r[13])

->setGoogle($r[63])

->setDescription($r[15])

->setShort_description($r[14])

 

->save();

 

################End Dutch#############

 

#############Netherland ################

$product->setStoreId(8)

->setName($r[7])

->setTitle_long($r[8])

->setGoogle($r[62])

->setDescription($r[10])

->setShort_description($r[9])

->save();

#############End Netherland##########

 

 

#####save your product###################

 

}catch(Exception $e){

$result[‘status’] = 3;

$result[‘message’] = ‘There is an ERROR happened! NOT ALL products are created! Error:’.$e->getMessage();

echo json_encode($result);

return;

}

exit;

}

If you go through the code you will find that all data are fetching from a spreadsheet with the code “$xlsx->rows()”. And data got to three different stores: 1)English (store id 1) 2)Dutch (store id 7) 3)Dutch (store id 8). Hope you like it. Thanks.

Magento Web Development: Upload Product From Front-End To Different Stores

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s