Monday, 15 June 2015

magento - Filter Orders based on product_id or user_id(Vendor) -



magento - Filter Orders based on product_id or user_id(Vendor) -

i have followed how create custom grid scratch create custom sales orders. admin creating vendors , vendors uploading product. want restrict vendors such can see orders placed on own product only. there 1 new model jbmarketplace/jbmarketplaceproducts in vendors user_id , product_id beingness stored when vendor creates product. when i'm filtering gives sqlstate[42s22]: column not found: 1054 unknown column 'product_id' in 'where clause'. product_id available in sales_flat_order_item table.

this problem fixed. updated code protected function _preparecollection() { // current logged in user $current_user = mage::getsingleton( 'admin/session' )->getuser(); // limit vendors if ( $current_user->getrole()->getroleid() == mage::getstoreconfig( 'jbmarketplace/jbmarketplace/vendors_role' ) ) { // echo( $current_user->getuserid()); $my_products = mage::getmodel( 'jbmarketplace/jbmarketplaceproducts' ) ->getcollection() ->addfieldtoselect( 'product_id' ) ->addfieldtofilter( 'user_id', $current_user->getuserid() ) ->load(); $my_product_array = array(); foreach ( $my_products $product ) { $my_product_array[] = $product->getproductid(); $entity = mage::getmodel('sales/order_item') ->getcollection() ->addfieldtoselect('order_id') ->addfieldtofilter('product_id',$my_product_array) ->load(); // echo $entity->getselect();// print sql query } $d=$entity->getdata(); if($d){ $collection = mage::getresourcemodel('sales/order_collection') // code ->addfieldtofilter('entity_id', $d) ->join(array('a' => 'sales/order_address'), 'main_table.entity_id = a.parent_id , a.address_type != \'billing\'', array( 'city' => 'city', 'country_id' => 'country_id' )) // ->join(mage::getconfig()->gettableprefix().'catalog_product_entity_varchar', 'main_table.products_id ='.mage::getconfig()->gettableprefix().'catalog_product_entity_varchar.entity_id',array('value')) ->join(array('c' => 'customer/customer_group'), 'main_table.customer_group_id = c.customer_group_id', array( 'customer_group_code' => 'customer_group_code' )) ->addexpressionfieldtoselect( 'fullname', 'concat({{customer_firstname}}, \' \', {{customer_lastname}})', array('customer_firstname' => 'main_table.customer_firstname', 'customer_lastname' => 'main_table.customer_lastname')) ->addexpressionfieldtoselect( 'products', '(select group_concat(\' \', x.name) sales_flat_order_item x {{entity_id}} = x.order_id , x.product_type != \'configurable\')', array('entity_id' => 'main_table.entity_id') ) ; parent::_preparecollection(); $this->setcollection($collection); homecoming $this; } else { echo("current there no purchases on product. give thanks you"); } } else{ echo("please login vendor , see orders on products.<br>"); // $current_user = mage::getsingleton( 'admin/session' )->getuser()->getuserid(); // echo($current_user); }

}

here code worked me.

protected function _preparecollection() { // current logged in user $current_user = mage::getsingleton( 'admin/session' )->getuser(); // limit vendors if ( $current_user->getrole()->getroleid() == mage::getstoreconfig( 'jbmarketplace/jbmarketplace/vendors_role' ) ) { // echo( $current_user->getuserid()); $my_products = mage::getmodel( 'jbmarketplace/jbmarketplaceproducts' ) ->getcollection() ->addfieldtoselect( 'product_id' ) ->addfieldtofilter( 'user_id', $current_user->getuserid() ) ->load(); $my_product_array = array(); foreach ( $my_products $product ) { $my_product_array[] = $product->getproductid(); $entity = mage::getmodel('sales/order_item') ->getcollection() ->addfieldtoselect('order_id') ->addfieldtofilter('product_id',$my_product_array) ->load(); // echo $entity->getselect();// print sql query } $d=$entity->getdata(); if($d){ $collection = mage::getresourcemodel('sales/order_collection') // code ->addfieldtofilter('entity_id', $d) ->join(array('a' => 'sales/order_address'), 'main_table.entity_id = a.parent_id , a.address_type != \'billing\'', array( 'city' => 'city', 'country_id' => 'country_id' )) // ->join(mage::getconfig()->gettableprefix().'catalog_product_entity_varchar', 'main_table.products_id ='.mage::getconfig()->gettableprefix().'catalog_product_entity_varchar.entity_id',array('value')) ->join(array('c' => 'customer/customer_group'), 'main_table.customer_group_id = c.customer_group_id', array( 'customer_group_code' => 'customer_group_code' )) ->addexpressionfieldtoselect( 'fullname', 'concat({{customer_firstname}}, \' \', {{customer_lastname}})', array('customer_firstname' => 'main_table.customer_firstname', 'customer_lastname' => 'main_table.customer_lastname')) ->addexpressionfieldtoselect( 'products', '(select group_concat(\' \', x.name) sales_flat_order_item x {{entity_id}} = x.order_id , x.product_type != \'configurable\')', array('entity_id' => 'main_table.entity_id') ) ; parent::_preparecollection(); $this->setcollection($collection); homecoming $this; } else { echo("current there no purchases on product. give thanks you"); } } else{ echo("please login vendor , see orders on products.<br>"); // $current_user = mage::getsingleton( 'admin/session' )->getuser()->getuserid(); // echo($current_user); } }

magento filtering

No comments:

Post a Comment