Showing posts with label store view. Show all posts
Showing posts with label store view. Show all posts

Tuesday, October 30, 2012

Add a new field to the store view

Here is the clear way to add a new field on the store view in Magento.
In order to do this you should create a new extension.
For the purpose of this demo I will use the 'namespace' Easylife. replace it with your own namespace if you want.
The extension is named Core because I'm overriding something in the core. You can name it how ever you want. Here are the files that need to be created:

app/code/local/Easylife/Core/etc/config:
<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Core>
            <version>0.0.1</version>
        </Easylife_Core>
    </modules>
    <global>
        <resources>
            <easylife_core_setup>
                <setup>
                    <module>Easylife_Core</module>
                </setup>
            </easylife_core_setup>
        </resources>
        <blocks>
            <adminhtml>
                <rewrite>
                    <system_store_edit_form>Easylife_Core_Block_Adminhtml_System_Store_Edit_Form</system_store_edit_form>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>
</config>
app/code/local/Easylife/Core/sql/easylife_core_setup/mysql4-install-0.0.1.php
<?php 
$this->startSetup();
$this->run("ALTER TABLE `{$this->getTable('core/store')}` ADD COLUMN `custom` VARCHAR(255)");//change the name and type of the column if you need.
$this->endSetup();
app/code/local/Easylife/Core/Block/Adminhtml/System/Store/Edit/Form.php - this overrides the admin block.
<?php 
class Easylife_Core_Block_Adminhtml_System_Store_Edit_Form extends Mage_Adminhtml_Block_System_Store_Edit_Form{
    protected function _prepareForm(){
        parent::_prepareForm();
        if (Mage::registry('store_type') == 'store'){
            $storeModel = Mage::registry('store_data');
            $fieldset = $this->getForm()->getElement('store_fieldset');
            $fieldset->addField('custom', 'text', array(
                    'name'      => 'store[custom]',
                    'label'     => Mage::helper('core')->__('Custom'),
                    'required'  => true,//or false
                    'value'        => $storeModel->getData('custom') 
                ));
        }
        return $this;
    }
}
In order to activate your module you need this file
app/etc/modules/Easylife_Core.xml
<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Core>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Core/>
            </depends>
        </Easylife_Core>
    </modules>
</config>
Enjoy.
Marius.

Monday, December 28, 2009

Switching language and currency when having multiple websitecodes (for sonician)

Problem (and maybe better solutions) found here:
http://www.magentocommerce.com/boards/viewthread/71171/

Hi again
There is a way of running a store view directly.
When you call something like this:
Mage::run('website1', 'website');
the default store view from website1 will run.
Let's say in website1 you have a store view called store_view_1. You can run it like this.
Mage::run('store_view_1');
As for the currency, you can set a default currency for each store view.
For example you can have to identical store views (in English), one with default currency 'EUR' and one 'GBP'.
Let's say the first one is called store_view_eur, and the second one store_view_gbp.
You can run them like this.
if (some condition){
Mage::run('store_view_eur');
}
else{
Mage::run('store_view_gbp');
}
As for the IP location, sorry but I don't think I can help you much there.

Thursday, December 24, 2009

Websitecode, currency, language (for sonician)

Problem:
get through code the current values for website, currency and language.
Hello,
Website:
//for name
Mage::app()->getWebsite()->getName();
//for code
Mage::app()->getWebsite()->getCode();
Currency:
Mage::app()->getStore()->getCurrentCurrencyCode();
Language:
This is a little tricky. You can get the ISO code for the language, because by standards French for France is different from French for Belgium
Mage::app()->getLocale()->getLocale();//will return something like fr_FR, fr_BE or en_US
if you want to go further and see only the language code it's simple
$isoCode = Mage::app()->getLocale()->getLocale();
$parts = explode("_", $isoCode);
$language = $parts[0];
$country = $parts[1];

Monday, November 23, 2009

Link customer login to store view? (for Pulse Digital Ltd)

This is a response for http://www.magentocommerce.com/boards/viewthread/67624/
Problem: Limit customers to only one store view.

I don't think you can limit a customer to a single store view, and limit his access only to that store view.
The whole idea of store view is that you have multiple versions (languages or currencies) for the same website.
What you can do is to set up 2 (or more) websites, each one with specific prices and/or products and allow the customer to access only that website.
You can find a tutorial here http://www.magentocommerce.com/knowledge-base/entry/overview-how-multiple-websites-stores-work and in the videos reffered here.
For example you set up mysite.com and mysite.eu. They can be hosted on the same machine and moderated form the same admin panel.
After that you can choose not to share the customer accounts from System->configuration->Customer configuration.
In the "Account Sharing Options" section set "Share Customer Accounts" to "Per Website".