0

I am working on magento extension, i check this code is written in grid.php file for product listing.

Mage::getModel('core/website')->getCollection()->toOptionHash()

When print_r this then it is given me array of website like

Array ( [1] => Website1 [14] => Website2 )

but i want this function should written only one one website. In which manner i change this line so that it give me single website details.

Example: $website_id = 14;

Then i place this variable into this line then it gives me details of that variable website only like,

Array ( [14] => Website2 )

Function line of module is ,

enter image description here

3 Answers 3

1

You can use this code to get detail of website by id

Mage::app()->getWebsite($website_id);

2
  • I cant use this line of code for achieve me website details. Kindly check my question.
    – Mathew
    Oct 26, 2015 at 13:37
  • The code you mentioned is from Grid.php and is meant to add column to grid to show the website of the product and use for filtration. therefore it must return array of websites. To view products on only once website, you can simply use website filter.
    – Haris
    Oct 29, 2015 at 5:25
1

Try this:

if (!Mage::app()->isSingleStoreMode()) {
    $websiteIds = array(14);
    $this->addColumn('websites',
        array(
            'header'=> Mage::helper('catalog')->__('Websites'),
            'width' => '100px',
            'sortable'  => false,
            'index'     => 'websites',
            'type'      => 'options',
            'options'   => Mage::getModel('core/website')->getCollection()->addIdFilter($websiteIds)->toOptionHash(),
    ));
}
0

you can get it like that

  $website_id = 14; //fetch the website data 
    $website = Mage::app()->getWebsite($website_id); 
    echo $website->getId(); 
echo $website->getDefaultGroup(); 
echo $website->getDefaultGroup()->getDefaultStore(); 
echo $website->getDefaultGroup()->getDefaultStore()->getId();
10
  • It is used in grid.php file. And return array format with its key and value like update question.
    – Mathew
    Oct 26, 2015 at 13:32
  • You want to add store of it? Too Oct 26, 2015 at 13:38
  • No actually i want to change above line of code, check in attached question image. So that it can provides me only one website details in array.
    – Mathew
    Oct 26, 2015 at 13:43
  • Above line of code is present in grid.php of product. It present in "app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php"
    – Mathew
    Oct 26, 2015 at 13:43
  • You are working with core files? What you want to achieve. Oct 26, 2015 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.