0

I made one more table in database which save sellers data then to load all seller's data I wrote following code and it is working like charm:

function getallSeller() {        
        $tableName = Mage::getSingleton("core/resource")->getTableName('Custom_sellerprofile');
        $model = Mage::getModel('customer/customer')->getCollection()->addFieldToFilter('customerstatus', array('eq' => 1));
        $model->getSelect()->join(array('t2' => $tableName),"e.entity_id = t2.seller_id and t2.store_title!=''", array('store_logo' => 't2.store_logo',  'store_title' => 't2.store_title','description' => 't2.description','city' => 't2.city','store_title' => 't2.store_title'));
        return $model;
    }

after that I added one more attribute REGION in my custom seller's table and then I want to fetch sellers by city(list of all sellers from particular region) for that I wrote this custom query but this is not working.

    function getSellerByRegion($region) { 
            $coreResource = Mage::getSingleton('core/resource');
            $connection = $coreResource->getConnection('core_read');

            $select = $connection->select()
                ->from( $coreResource->getTableName('Custom_sellerprofile'))
                ->where('region = ?', $region);

            $customers=$connection->fetchAll($select);
            $model = Mage::getModel('customer/customer')->getCollection()->addFieldToFilter('customerstatus', array('eq' => 1));

            $model->getSelect()->join(array('t2' => $customers),"e.entity_id = t2.seller_id and t2.store_title!=''", array('store_logo' => 't2.store_logo',  'store_title' => 't2.store_title','description' => 't2.description','city' => 't2.city','store_title' => 't2.store_title'));

            return $model  }

getting this Error:

Syntax error or access violation: 1103 Incorrect table name '', query   was: SELECT `e`.*, `at_customerstatus`.`value` AS `customerstatus`, `t2`.`store_logo`, `t2`.`store_title`, `t2`.`description`, `t2`.`region` FROM `customer_entity` AS `e`

I guess that if we add that(custom) attribute in customer model then it can work but instead of that want to do from here only.

This is my first custom query so please don't hit much;)

  • Custom_sellerprofile is your table name in config.xml ? – liyakat May 27 '15 at 8:16
  • yes @liyakat that is why all sellers details are fetching and I double checked it is there. – Pushpendra May 27 '15 at 8:18
  • is customerstatus your custom customer attribute ? – liyakat May 27 '15 at 11:49
  • error is in your ->join(array('t2' => $customers) it should be your any table name like ->join(array('t2' => $coreResource->getTableName('Custom_sellerprofile') and then add your rest of condition to it – liyakat May 27 '15 at 11:52
  • @liyakat I did it already i will upload my solution soon and yeah your solution is very near. thanks for your reply – Pushpendra May 27 '15 at 12:36
1

I did silly mistake which I figured it out after uploading my question.

Almost all things are okay here just need these little modification:

  1. 1st do need to fetch data directly (so I removed this line code:)
    $customers=$connection->fetchAll($select);
  2. So while joining put $select instead of $costumers

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.