cancel
Showing results for 
Search instead for 
Did you mean: 

How to programatically add multiple views for existing website

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

Re: How to programatically add multiple views for existing website

Figured it out myself