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

1

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

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

| improve this answer | |
  • I cant use this line of code for achieve me website details. Kindly check my question. – Mathew Oct 26 '15 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 '15 at 5:25
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();
| improve this answer | |
  • It is used in grid.php file. And return array format with its key and value like update question. – Mathew Oct 26 '15 at 13:32
  • You want to add store of it? Too – Qaisar Satti Oct 26 '15 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 '15 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 '15 at 13:43
  • You are working with core files? What you want to achieve. – Qaisar Satti Oct 26 '15 at 13:51
0

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(),
    ));
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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