Search

shamjascp

This WordPress.com site is the bee's knees

Month

April 2016

How to set multiple websites with multiple store views in Magento

How to set multiple websites with multiple store views in Magento

 

If you work with Magento, sooner or later you will end up needing multiple websites that have
multiple languages.
Most of you know this, but I hope someone will still find this post useful.

There are few ways of doing same thing, but in my experience way I’m going to present now causes
less problems even though it is less automatic than some other ways.

Let’s say we want 2 websites and 2 languages for each site.

Here’s procedure:

In admin panel, go to System->Configuration and click on “Manage Stores”
Click on “Main Website” to change it’s name to “Website 1” or however you want to call it. (I’ll call mine “Website 1” for the purposes of this article).
In “code” field there, write something like “website_1”.

Do same for “Main Website Store”. Call it “Website store 1”.

And guess what… do same for “Default Store View” that you can find on same interface.
How to call it?
Hm… I’ll call mine “English Store View”
I’ll write “english_store_view_website_1” in “code” field there.

Ok, let’s go make second one…
Add website named “Website 2” with code “website_2”.
Add store called “Website store 2” and assign it to Website 2 that you can chose from dropdown.
Add new store view called “English Store View” with code “english_store_view_website_2” and
assign it to “Website 2” that you can find in dropdown.

By now you should have 2 websites with 1 language each.

Add two more store views.
Call first “German Store View” with code “german_store_view_website_1”.
Call second “German Store View” with code “german_store_view_website_2”.
Assign them to corresponding websites.

Let’s see what we have at this moment:

1) a) Website 1 (code: website_1) – Website Store 1 English Store View (code: english_store_view_website_1)
b) Website 1 (code: website_1) – Website Store 1German Store View (code: german_store_view_website_1)

2) a) Website 2 (code: website_2) – Website Store 2 English Store View (code: english_store_view_website_2)
b) Website 2 (code: website_2) – Website Store 2German Store View (code: german_store_view_website_2)

Of course, I didn’t mentioned that you will need to chose root category for your stores, do what ever you like there.

Ok, let’s say we want url to be handled this way:
1) http://www.yourdomain.com/website_1
2) http://www.yourdomain.com/website_2

In your Magento installation directory, make 2 directories called “website_1” and “website_2”
Copy .htacces and index.php from your root directory in each of those new directories.

In .htaccess search for “RewriteBase /” line and replace it with “RewriteBase /website_1/” in first directory, and
search for “RewriteBase /” line and replace it with “RewriteBase /website_2/” in second directory.

In both directories open index.php and change “$compilerConfig = ‘includes/config.php’;” to
$compilerConfig = ‘../includes/config.php’;(remove magentoroot variable)

Change $mageFilename = ‘app/Mage.php’; to $mageFilename = ‘../app/Mage.php’;

In same file make sure to edit Mage::run() function for each site:

Mage::run(‘website_1’, ‘website’);
Mage::run(‘website_2’, ‘website’);

Go to System->Configuration and select Current Configuration Scope: Website 1

Set absolute paths to your skin, js and  media directories and set Base URL =http://www.yourdomain.com/website_1  (do that for website_2 too)

Now use this dirty way to switch between websites :)
http://inchoo.net/ecommerce/magento-snippet-for-switching-between-websites/

Since there is much to say about this subject, feel free to ask questions and I’ll try to answer them asap.

Magento sharing shopping cart with multiple Website

http://stackoverflow.com/questions/12374289/magento-multiple-websites-share-shopping-cart

 

 

After I searched for an answer to this and stumbled across the same question being asked since 2009 without a definite solution, I finally had to look into the deep end of the code myself – and voila, I have a working solution. Here a detailed guide for anyone who wants to set up Magento with

  • multiple currencies that don’t just get displayed but actually charged in the selected currency
  • share the shopping cart throughout websites and not just stores

The main problem with this combination is that with the default Magento structure you can only ever do one or the other, not the two combined.

So lets set Magento up for multiple currencies first.

  • Create a website for each currency with a corresponding store and store view (not just store views, complete websites)
  • Set System – Configuration – Currency Setup per website to the respective currency. All three entries Base Currecny, Default Display Currency and Allowed currencies should be set to just one and the same currency.
  • Go back to the default overall config scope and set System – Configuration – Catalog – – – Price the Catalog Price Scope to “Website”
  • You can also define you currency rates in System – Manage Currency Rates
  • For each website scope set the appropriate System – Configuration – Web – Secure and Unsecure base url.
  • In your .htaccess file add this at the top (replace the appropriate website domains and code you entered when setting up the websites (here http://website-us.local with base_us andhttp://website-uk.local with code base_uk)

    SetEnvIf Host website-us.local MAGE_RUN_CODE=base_us SetEnvIf Host website-us.local MAGE_RUN_TYPE=website SetEnvIf Host ^website-us.local MAGE_RUN_CODE=base_us SetEnvIf Host ^website-us.local MAGE_RUN_TYPE=website

    SetEnvIf Host website-uk.local MAGE_RUN_CODE=base_uk SetEnvIf Host website-uk.local MAGE_RUN_TYPE=website SetEnvIf Host ^website-uk.local MAGE_RUN_CODE=base_uk SetEnvIf Host ^website-uk.local MAGE_RUN_TYPE=website

  • Overwrite the method convertPrice in Mage/Core/Model/Store and change the method convertPrice – this will ensure that the prices are always displayed in the correct conversion AND the correct currency sign.
    /**
     * Convert price from default currency to current currency
     *
     * @param   double $price
     * @param   boolean $format             Format price to currency format
     * @param   boolean $includeContainer   Enclose into <span class="price"><span>
     * @return  double
     */
    public function convertPrice($price, $format = false, $includeContainer = true)
    {
        $categories = Mage::getModel('catalog/category')->getCollection();
        $categ_ids=$categories->getAllIds();
        $baseCurrencyCode = Mage::app()->getBaseCurrencyCode();
        $allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
        $currencyRates = Mage::getModel('directory/currency')->getCurrencyRates($baseCurrencyCode,array_values($allowedCurrencies));
    
        if ($this->getCurrentCurrency() && $this->getBaseCurrency()) {
            $value = $this->getBaseCurrency()->convert($price, $this->getCurrentCurrency());
        } else {
            $value = $price;
        }
    
    
        if($this->getCurrentCurrencyCode() != $baseCurrencyCode)
        {
            $value = $price * $currencyRates[$this->getCurrentCurrencyCode()];
        }
        if ($this->getCurrentCurrency() && $format) {
            $value = $this->formatPrice($value, $includeContainer);
        }
        return $value;
    }

    }

But of course we also want to share the users data, cart and login throughout the websites we just set up.

  • While in default config scope set System – Configuration – Customer Configuration – Account Sharing Options – Share Customer Accounts to Global
  • Overwrite magento/app/code/core/Mage/Checkout/Model/Session.php and replace this method:

    protected function _getQuoteIdKey() { return ‘quote_id’; //return ‘quote_id_’ . $websites[1]; }

  • Overwrite magento/app/code/core/Mage/Sales/Model/Quote.php and change the method getSharedStoreIds to:

    public function getSharedStoreIds() { $ids = $this->_getData(‘shared_store_ids’); if (is_null($ids) || !is_array($ids)) { $arrStoreIds = array(); foreach(Mage::getModel(‘core/website’)->getCollection() as $website) { $arrStoreIds = array_merge($arrStoreIds,$website->getStoreIds()); } return $arrStoreIds; /*if ($website = $this->getWebsite()) { return $website->getStoreIds(); } var_dump($this->getStore()->getWebsite()->getStoreIds());exit(); return $this->getStore()->getWebsite()->getStoreIds(); */ } return $ids; }

  • Overwrite magento/app/code/core/Mage/Customers/Model/Customer.php and change again the method getSharedWebsiteIds() to:

    public function getSharedWebsiteIds() { $ids = $this->_getData(‘shared_website_ids’); if ($ids === null) { $ids = array(); if ((bool)$this->getSharingConfig()->isWebsiteScope()) { $ids[] = $this->getWebsiteId(); } else { foreach (Mage::app()->getWebsites() as $website) { $ids[] = $website->getId(); } } $this->setData(‘shared_website_ids’, $ids); } return $ids; }

  • If you use the wishlist option you should do the same for the method in magento/app/code/core/Mage/Wishlist/Model/Wishlist.php and change getSharedWebsiteIds so it not only loads the store ids from the current website but from all of them
  • Now we also have to implement a currency (website) switch on the frontend stores and pass the correct session ids inbetween so magento knows what stores to look for. I imitated the currency switch here and added the following dropdown to

magento/app/design/frontend/default/yourtheme/template/directory/currency.phtml

This loads all websites and applies the current Session Id as a query string so magento knows on any domain which session to use.

<?php
/**
 * Currency switcher
 *
 * @see Mage_Directory_Block_Currency
 */
?>
class="top-currency"> php $websites = Mage::getModel('core/website')->getCollection(); $this_session_id = Mage::getSingleton('core/session', array('name' => 'frontend'))->getSessionId(); ?> id="website-changer" onChange="document.location=this.options[selectedIndex].value"> php foreach($websites as $website): $default_store = $website->getDefaultStore(); $website_currency = $default_store->getBaseCurrency()->getCurrencyCode(); $url_obj = new Mage_Core_Model_Url(); $default_store_path = $url_obj->getBaseUrl(array('_store'=> $default_store->getCode())); $default_store_path .= Mage::getSingleton('core/url')->escape(ltrim(Mage::app()->getRequest()->getRequestString(), '/')); $default_store_path = explode('?', $default_store_path); $default_store_path = $default_store_path[0] . '?SID=' . $this_session_id; ?> if(strstr($default_store_path,Mage::getBaseUrl())):?>selected="selected"endif; ?> value="$default_store_path ?>"> $website_currency?> endforeach;?>

This query string will only be applied the first time you switch but magento will remember the session id after that stored in a cookie.

  • In order for this to work properly, overwrite

magento/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php

and

replace this

// potential custom logic for session id (ex. switching between hosts)
$this->setSessionId();

with

// potential custom logic for session id (ex. switching between hosts)
/* Amend to ensure shopping carts are shared between websites */
if (isset($_COOKIE['lastsid']))
{
  session_decode(file_get_contents(Mage::getBaseDir('session').'/sess_'.$_COOKIE['lastsid']));
            setcookie ('lastsid', '', time() - 3600);
        }

        if (isset($_GET['SID']))
        {
            $this->setSessionId($_GET['SID']);
            session_decode(file_get_contents(Mage::getBaseDir('session') . '/sess_' . $_GET['SID']));
            setcookie('lastsid', $_GET['SID']);
            $_COOKIE['lastsid'] = $_GET['SID'];
        }
        else
        {
            $this->setSessionId();
        }
        /* Amend end */

This should now display multiple currencies, charge in multiple currencies across mutliple websites and on top of this share logins and shopping carts. This solution is a collection of knowledge I found on the interwebs combined with a few bits and pieces I figured out myself, so thanks for anyone who gave advice!

CREATE LANDING PAGE WITH EASE IN MAGENTO

http://www.webinse.com/blog/magento/landing-page-creation-using-magento/

 

The main purpose of creating an online-shop is to make customers not only go to your store from Google. The main purpose is to make your customers stay and buy some of your goods. You can encourage them to explore the products using landing pages. Landing page –  is the first impression about your store. Ideally, your landing page should target your visitors to a product pages.

Landing page closely connected with “About Us” page. These pages are created to tell visitors about your store. They may include contacts, billing, shipping, company’s history, etc. These pages can tell visitors about your business practices and to make your store more respected. In this article I will show you how to create landing page with the help of Magento CMS page.

Landing page is not a product page. Visitor does not choose a color of goods and does not add something to shopping cart.

Instead, it should make visitors to buy your product. You can read my articles about how to make your website more attractive for customers:

1. How to make your website successful?

https://www.webinse.com/blog/ecommerce/how-to-make-your-website-successful/

2. Improve your store performance in Magento

https://www.webinse.com/blog/ecommerce/improve-store-performance-magento/

3. Optimize your frontend performance with Magento

https://www.webinse.com/blog/ecommerce/optimize-frontend-performance-magento/

Landing page often matches to a particular advertisement. For example, we added advertising on a website for business owners:

landing page 1

By clicking this ad visitors enter a landing page in the store:

landing page 2

The top of the landing page (above the list of products) is a basic landing page. First of all, we will see how to create this part of the page. The bottom of this landing page consists of dynamic content.

How To Create Basic Landing Page In Magento

To understand how to create basic landing page in Magento, you should understand how to create Magento CMS page (static).

Creating of a CMS page is described in my article:

https://www.webinse.com/blog/ecommerce/php-code-magento-cms-page/

Adding a template to the CMS page:

  1. Select Custom Design tab.
  2. If you want to use custom theme, select it in the drop-down menu.
  3. In the drop-down list Layout, select type of layout you want to see in your page.
  4. Save and view. You should see that the template was applied to the Magento CMS page. Content that you entered appears in Magento page. Now you have a basic landing page.

landing page 3

Basic landing page that we created is static. It has no dynamic content – the content that is formed during browsing of the page. You can make your landing page dynamic by adding Magento dynamic blocks like products and product categories.

How To Add Dynamic Content To Landing Page In Magento

Create a product category for landing page:

  1. Choose Catalog – Manage Categories.
  2. Add a new subcategory in the Default category.
  3. In the Name field you can write “landing page” or something similar. While assigning products in this category, you will see this title.
  4. In the Active, select No. This will prevent displaying of categories in the navigation menu. Remember that you want to use this category only for your landing page.
  5. Key URL does not matter. This category will have its own page. It will be built into the landing page.
  6. You can fill in the Description. That will help you to remember the purpose of the category.
  7. You can skip the rest of the fields and tabs. Click Save.

landing page 4

Add products to the landing page category :

  1. Select Catalog – Manage Products. Manage Products page will be opened.
  2. For a product to be displayed on the page, click the Edit. Page is displayed Product Information. You will see a General tab.
  3. Select Categories.
  4. Select a category that you have created for your landing page. It should be gray because the category is not active
  5. Save the product.
  6. Repeat this procedure for each product that you want to see on the landing page.

landing page 5

So, our page works almost the same way as a usual category page. Remember that the landing page displays the products from the chosen category.

3 Thoughts On “Create Landing Page With Ease In Magento”

  • computer software

    Howdy! This is kind of off topic but I need
    some guidance from an established blog. Is it difficult to set up your own blog?
    I’m not very techincal but I can figure things out pretty quick.
    I’m thinking about making my own but I’m not sure where to start.
    Do you have any points or suggestions? With thanks

    Reply
  • Magento website design

    Nice info you have shared over here, it would be very helpful information for Magento web designers.

    Reply
  • bing.com

    Hello colleagues, its great article regarding teachingand completely defined, keep it up all the time.

Free magento themes

Download Elantra – Advanced Responsive Magento Theme 2016

Blog at WordPress.com.

Up ↑