我正在尋找一種按名稱獲取Magento對象(商店,網站,組)的方法。是的,我知道我可以得到整個集合,然後遍歷它,但對我來說這似乎相當愚蠢。我嘗試了一些實驗,但都無濟於事。當然,必須有某種方式讓數據庫爲我找到這個對象,而不必返回一個完整的集合並手動迭代它。Magento - 按名稱獲取商店,網站,組對象
到目前爲止,我已經嘗試瞭如下代碼的寶石,都沒有任何運氣。
$site = Mage::getResourceModel('core/website_collection')->addFieldFilter('name', "Test Website");
$site = Mage::getResourceModel('core/website')->loadByAttribute('name', 'Test Store');
這不會返回一組網站嗎?最有可能的是一個項目集合,當然,但我想象得到實際的網站對象,你需要添加getFirstItem(): '$ site = Mage :: getResourceModel('core/website_collection') - > addFieldToFilter('name','Test Website') - > getFirstItem();' –