gpt4 book ai didi

magento - 根据 product_id 或 user_id(供应商)过滤订单

转载 作者:行者123 更新时间:2023-12-02 03:34:45 26 4
gpt4 key购买 nike

我关注了How to create a custom grid from scratch创建自定义销售订单。管理员正在创建供应商,供应商将上传产品。我想限制供应商,使他们只能看到对自己产品的订单。有一种新模型 jbmarketplace/jbmarketplaceproducts,其中供应商创建产品时存储了供应商 user_id 和 product_id。但是当我过滤时它给出了 SQLSTATE[42S22]: Column not found: 1054 Unknown column 'product_id' in 'where clause'。但是 product_id 在 sales_flat_order_item 表中可用。

此问题已修复。更新代码

protected function _prepareCollection()
{
// Get current logged in user
$current_user = Mage::getSingleton( 'admin/session' )->getUser();

// Limit only for 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 as $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();// will print sql query

}
$d=$entity->getData();

if($d){

$collection = Mage::getResourceModel('sales/order_collection')
// My code
->addFieldToFilter('entity_id', $d)
->join(array('a' => 'sales/order_address'), 'main_table.entity_id = a.parent_id AND 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)
FROM sales_flat_order_item x
WHERE {{entity_id}} = x.order_id
AND x.product_type != \'configurable\')',
array('entity_id' => 'main_table.entity_id')
)

;
parent::_prepareCollection();
$this->setCollection($collection);
return $this;

}
else
{
echo("Current there are no purchases on your product. Thank you");
}
}
else{
echo("Please Login as Vendor and you will see orders on your products.<br>");
// $current_user = Mage::getSingleton( 'admin/session' )->getUser()->getUserId();
// echo($current_user);
}

最佳答案

这是对我有用的代码。

protected function _prepareCollection()
{
// Get current logged in user
$current_user = Mage::getSingleton( 'admin/session' )->getUser();

// Limit only for 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 as $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();// will print sql query

}
$d=$entity->getData();

if($d){

$collection = Mage::getResourceModel('sales/order_collection')
// My code
->addFieldToFilter('entity_id', $d)
->join(array('a' => 'sales/order_address'), 'main_table.entity_id = a.parent_id AND 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)
FROM sales_flat_order_item x
WHERE {{entity_id}} = x.order_id
AND x.product_type != \'configurable\')',
array('entity_id' => 'main_table.entity_id')
)

;
parent::_prepareCollection();
$this->setCollection($collection);
return $this;

}
else
{
echo("Current there are no purchases on your product. Thank you");
}
}
else{
echo("Please Login as Vendor and you will see orders on your products.<br>");
// $current_user = Mage::getSingleton( 'admin/session' )->getUser()->getUserId();
// echo($current_user);
}
}

关于magento - 根据 product_id 或 user_id(供应商)过滤订单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24365892/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com