1

We saved some values in backend, we are displaying those values in frontend using code written in phtml file.

Now we shifted code to block file, but now those dropdown options are displaying in different positions as here

1) Is i am displaying code in wrong place ?

2) Is i need to call those block in phtml ?

class Company_Brand_Block_Frontend_Detail extends Mage_Core_Block_Template {

    protected $_faq;
    protected $_images;


    protected function _prepareLayout()
    {
          $brand = $this->getBrand();

        if ($brand !== false && $head = $this->getLayout()->getBlock('head')) {
            $head->setTitle($this->htmlEscape($brand->getBmodel()) . ' - ' . $head->getTitle());
        }
    }

    /**
     * Function to gather the current Brand item
     *
     * @return Company_Brand_Model_Brand The current brand item
     */
    public function getBrand() {
        if (!$this->_brand) {
            $id = intval($this->getRequest()->getParam('brand'));
            try {
                $this->_faq = Mage :: getModel('brand/brand')->load($id); 

                if ($this->_faq->getIsActive() != 1){
                    Mage::throwException('Brand Item is not active');
                }
            }
            catch (Exception $e) {
                $this->_brand = false;
            }
        }

        return $this->_brand;
    }
}


$resource = Mage::getSingleton('core/resource');

$readConnection = $resource->getConnection('core_read');

$writeConnection = $resource->getConnection('core_write');

$readConnection = $resource->getConnection('core_read');

$query = 'SELECT category_id, category_name FROM ' . $resource->getTableName('Company_advance_brand_category');

$categories = $readConnection->fetchAll($query);

$brandsArr = array();

$brandSelect = '<select id="brand_select">';
$brandSelect .= '<option value="">My Brand</option>';
foreach ($categories as $category){
$cat_id = $category["category_id"];

$brandSelect .= "<option value='".$category["category_id"]."'>".$category["category_name"]."</option>";

$query = 'SELECT `Company_advance_brand`.brand_id, `Company_advance_brand`.bmodel FROM `Company_advance_brand` ';
$query .= ' inner join `Company_advance_brand_category_item` on
(`Company_advance_brand`.brand_id = `Company_advance_brand_category_item`.brand_id )';
$query .= ' where `Company_advance_brand_category_item`.category_id = '.$cat_id;

$brands = $readConnection->fetchAll($query);

$bArr = array();

foreach ($brands as $brand){
$bArr[$brand["brand_id"]] = $brand["bmodel"];
}
$brandsArr[$cat_id] = $bArr;
}
$brandSelect .= '</select>';

echo $brandSelect;
echo '<select id="model_select"><option value="">My Model</option></select>';
1

create a new method in block and call that in phtml file like echo $this->getOptions();

class Outthink_Brand_Block_Frontend_Detail extends Mage_Core_Block_Template {


    public function getOptions()
    {
       $resource = Mage::getSingleton('core/resource');

$readConnection = $resource->getConnection('core_read');

$writeConnection = $resource->getConnection('core_write');

$readConnection = $resource->getConnection('core_read');

$query = 'SELECT category_id, category_name FROM ' . $resource->getTableName('outthink_advance_brand_category');

$categories = $readConnection->fetchAll($query);

$brandsArr = array();

$brandSelect = '<select id="brand_select">';
$brandSelect .= '<option value="">My Brand</option>';
foreach ($categories as $category){
$cat_id = $category["category_id"];

$brandSelect .= "<option value='".$category["category_id"]."'>".$category["category_name"]."</option>";

$query = 'SELECT `outthink_advance_brand`.brand_id, `outthink_advance_brand`.bmodel FROM `outthink_advance_brand` ';
$query .= ' inner join `outthink_advance_brand_category_item` on
(`outthink_advance_brand`.brand_id = `outthink_advance_brand_category_item`.brand_id )';
$query .= ' where `outthink_advance_brand_category_item`.category_id = '.$cat_id;

$brands = $readConnection->fetchAll($query);

$bArr = array();

foreach ($brands as $brand){
$bArr[$brand["brand_id"]] = $brand["bmodel"];
}
$brandsArr[$cat_id] = $bArr;
}
$brandSelect .= '</select>';

return $brandSelect.'<select id="model_select"><option value="">My Model</option></select>';

    }
}
| 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.