Friday 1 June 2012

Magento: Create multiple website

I suppose that you have installed magento.
Login to Admin Panel.

Step 1: Create Website
- Go to System –> Manage Stores
- Click on Create Website button and provide below details:
- Name = e.x. WebsiteOne
- Code = e.x. website_one
- Sort Order = e.x. 1 

- Once you done with then click on Save Website button.
- Please find the below screen-shot for the same:


Step 2: Create Store
- Go to System –> Manage Stores
- Click on Create Store button and provide below details:
- Website = Choose the website which we have created in Step 1 say for e.x.    WebsiteOne.
- Name = e.x. WebsiteOneStore
- Root Category = Select appropriate category for website OR choose the default category.

- Once you done with then click on Save Store button.
- Please find the below screen-shot for the same: 


Step 3: Create Store View
- Go to System –> Manage Stores
- Click on Create Store View button and provide below details:
- Store = Choose the store which we have created in Step 2 say for e.x.    WebsiteOneStore.
- Name = e.x. WebsiteOneStoreView
- Code = e.x. website_one_store_view

- Status = Select Enabled option.
- Sort Order = e.x. 1 

- Once you done with then click on Save Website button.
- Please find the below screen-shot for the same: 

Step 4: Change Link URL
- Go to System –> Configuration
- Change 'Current Configuration Scope' to 'WebsiteOne' (in left hand corner).
- Go to System –> Configuration -> GENERAL -> Web
- Goto to Unsecure and Secure tab (present in right hand side)
- Change Base Link URL = e.x. http://yourwebsite.com/magento/websiteone/ (i.e. websiteone is a folder name which we have given for our new website).
- Once you done with then click on Save Config button.
- Please find the below screen-shot for the same:


Step 5: Create a new folder named 'websiteone' inside 'magento (OR whatever project name given)' folder.
- Copy index.php and .htaccess file from your magento folder to websiteone folder.

Step 6: Open index.php of websiteone folder:
- Change $compilerConfig = 'includes/config.php'; to $compilerConfig = '../includes/config.php';
- Change $mageFilename = 'app/Mage.php'; to $mageFilename = '../app/Mage.php';
- Change Mage::run(); to Mage::run('website_one','website’); 

- Clean up your Cache.

Finally, you have created a new website for your magento shop. Your base website can be browsed by http://yourwebsite.com/magento/ and your new website can be browsed by http://yourwebsite.com/magento/websiteone/


Hope this help!
Njoy!


 

Thursday 12 January 2012

Magento: Skip Shipping Method from onepage checkout

(Tried for comm. ver. 1.5.1.0)

First override following files(i.e. in local directory) rather than changing the core:
1) app/code/core/Mage/Checkout/Block/Onepage/Onepage.php
2) app/code/core/mage/checkout/controller/Onepagecontrollers.php
3) app/code/core/Mage/Sales/Model/Service/Quote.php
4) app/design/frontend/base/default/template/checkout/onepage/progress.phtml
5) app/code/core/Mage/Sales/Model/Service/Quote.php

Once done follow the below steps:

Step 1: app/code/local/Mage/Checkout/Block/Onepage/Onepage.php

Change the line:
$stepCodes = array('billing', 'shipping', 'shipping_method', 'payment', 'review');

with:
$stepCodes = array('billing', 'shipping', 'payment', 'review');


Step 2: app/code/local/Mage/Checkout/controller/Onepagecontrollers.php

Change the line:
protected $_sectionUpdateFunctions = array(
'payment-method' => '_getPaymentMethodsHtml',
'shpping-method' => '_getShippingMeghtoHtml',
'review' => '_getReviewHtml',
);

with:
protected $_sectionUpdateFunctions = array(
'payment-method' => '_getPaymentMethodsHtml',
'review' => '_getReviewHtml',
);


Step 3: app/code/local/Mage/Checkout/controller/Onepagecontrollers.php

Change saveBillingAction() function with:

public function saveBillingAction()
{
if ($this->_expireAjax()) {
return;
}
if ($this->getRequest()->isPost()) {
$postData = $this->getRequest()->getPost('billing', array());
$data = $this->_filterPostData($postData);
$data = $this->getRequest()->getPost('billing', array());
$customerAddressId = $this->getRequest()->getPost('billing_address_id', false);

if (isset($data['email'])) {
$data['email'] = trim($data['email']);
}
$result = $this->getOnepage()->saveBilling($data, $customerAddressId);

if (!isset($result['error'])) {
/* check quote for virtual */
if ($this->getOnepage()->getQuote()->isVirtual()) {
$result['goto_section'] = 'payment';
$result['update_section'] = array(
'name' => 'payment-method',
'html' => $this->_getPaymentMethodsHtml()
);
} elseif (isset($data['use_for_shipping']) && $data['use_for_shipping'] == 1) {
$result['goto_section'] = 'payment';
$result['update_section'] = array(
'name' => 'payment-method',
'html' => $this->_getPaymentMethodsHtml()
);

$result['allow_sections'] = array('shipping');
$result['duplicateBillingInfo'] = 'true';
} else {
$result['goto_section'] = 'shipping';
}
}

$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
}

Change saveShippingAction() function with:

public function saveShippingAction()
{
if ($this->_expireAjax()) {
return;
}
if ($this->getRequest()->isPost()) {
$data = $this->getRequest()->getPost('shipping', array());
$customerAddressId = $this->getRequest()->getPost('shipping_address_id', false);
$result = $this->getOnepage()->saveShipping($data, $customerAddressId);

if (!isset($result['error'])) {
$result['goto_section'] = 'payment';
$result['update_section'] = array(
'name' => 'payment-method',
'html' => $this->_getPaymentMethodsHtml()
);
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
}

Step 4: app/code/local/Mage/Sales/Model/Service/Quote.php

Change _validate() function with:

protected function _validate()
{
$helper = Mage::helper('sales');
if (!$this->getQuote()->isVirtual()) {
$address = $this->getQuote()->getShippingAddress();
$addressValidation = $address->validate();
if ($addressValidation !== true) {
Mage::throwException(
$helper->__('Please check shipping address information. %s', implode(' ', $addressValidation))
);
}
}

$addressValidation = $this->getQuote()->getBillingAddress()->validate();
if ($addressValidation !== true) {
Mage::throwException(
$helper->__('Please check billing address information. %s', implode(' ', $addressValidation))
);
}

if (!($this->getQuote()->getPayment()->getMethod())) {
Mage::throwException($helper->__('Please select a valid payment method.'));
}

return $this;
}


Step 5: app/design/frontend/default/default/template/checkout/onepage/progress.phtml

Remove the shipping method block.

Step 6: app/locale/en_US/template/email/sales/order_new.html

Remove the shipping method block(i.e. {{var order.getShippingDescription()}}).


Hope this help!
Njoy!

Wednesday 11 January 2012

Magento: Programmatically Reindex Data

In this post you will learn how to reindex Magento Data Programmatically other way you can also do it manually(System -> Index Management).


Below you will find the Index name and their respective keys which will be require to do the same programmatically:

Index Name Index Key
Product Attributes 1
Product Prices 2
Catalog URL Rewrites 3
Product Flat Data 4
Category Flat Data 5
Category Products 6
Catalog Search index 7
Tag Aggregation Data 8
Stock Status 9

So, if you want to do re indexing of  “Category Products” then follow the below method:-
$process = Mage::getModel('index/process')->load(6);
$process->reindexAll();
Make a loop if you want to do the re indexing of all the entities:-
for ($i = 1; $i <= 9; $i++) {
    $process = Mage::getModel('index/process')->load($i);
    $process->reindexAll();
}

Hope this help!
Njoy!

Wednesday 4 January 2012

Magento - Add Categories as Static Block

In this session you will know how to add categories as static block i.e. in particular category just show only content which can be easily managed through admin panel,
so please follow the below step to achieve the same:

Step 1:
Login to Magento's:
CMS->Static Blocks





Step 2:
Add new block and save it



Step 3:
Goto Catalog->Manage Categories

Step 4:
Create new categories by filling the general informatiom in General Information Tab.


Now click on other tab named Display Settings, select Display Mode option as Static block only.
Once you select it you will see your added static block name in CMS Block option so select your block and save it.






You have done with it.

See output at frontend:




Hope this help!
Njoy!