Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use collection _idFieldName by default for toOption* methods. #182

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion lib/Varien/Data/Collection/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,37 @@ public function fetchItem()
return false;
}

/**
* Overridden to use _idFieldName by default.
*
* @param string $valueField
* @param string $labelField
* @param array $additional
* @return array
*/
protected function _toOptionArray($valueField = NULL, $labelField = 'name', $additional = array())
{
if ($valueField === NULL) {
$valueField = $this->getIdFieldName();
}
return parent::_toOptionArray($valueField, $labelField, $additional);
}

/**
* Overridden to use _idFieldName by default.
*
* @param string $valueField
* @param string $labelField
* @return array
*/
protected function _toOptionHash($valueField = NULL, $labelField = 'name')
{
if ($valueField === NULL) {
$valueField = $this->getIdFieldName();
}
return parent::_toOptionHash($valueField, $labelField);
}

/**
* Convert items array to hash for select options
* unsing fetchItem method
Expand All @@ -622,8 +653,11 @@ public function fetchItem()
* @param string $labelField
* @return array
*/
protected function _toOptionHashOptimized($valueField='id', $labelField='name')
protected function _toOptionHashOptimized($valueField=NULL, $labelField='name')
{
if ($valueField === NULL) {
$valueField = $this->getIdFieldName();
}
$result = array();
while ($item = $this->fetchItem()) {
$result[$item->getData($valueField)] = $item->getData($labelField);
Expand Down