cancel
Showing results for 
Search instead for 
Did you mean: 

How to programatically add multiple views for existing website

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

How to programatically add multiple views for existing website

I am wondering if you could assist with this exercise. Here's what I have so far

 

<?php
    // Get default website ID
    $website_id = Mage::app()->getWebsite()->getId();
    if ($website_id < 1)
    {
        throw new Exception('No website configured');
    }

    // Get default group ID
    $group_id = Mage::app()->getGroup()->getId();
    if ($group_id < 1)
    {
        throw new Exception('No group configured');
    }

    $configuration = [
        'languages' => ['en', 'fr', 'sp']
    ];

    $view_name = 'mahstow';
// Add views to the website/group
    foreach ($configuration['languages'] as $language)
    {
        $view_code = (($language == 'en') ? strtolower($view_name) : strtolower($view_name) . "_{$language}");
        $saved_store = $store->setCode($view_code)
            ->setWebsiteId($website_id)
            ->setGroupId($group_id)
            ->setName($view_name)
            ->setIsActive(1)
            ->save();
        if ($saved_store->getId() < 1)
        {
            throw new Exception("Store view could not be created");
        }
    } 
1 REPLY 1

Re: How to programatically add multiple views for existing website

Figured it out myself