获取当前产品的所有者ID?

时间:2013-08-17 05:18:36

标签: php magento

在我的购物网站上,我有100个产品。从那我选择了一个产品。如何获取该产品的用户ID?

我仍然需要做更多的事情,这是在卖家页面。

我尝试了这段代码,但它没有用。

<?php 
    $product_id = $this->getProduct()->getId();
    echo $product_id; // It's displaying Product ID
    $productowner=Mage::getModel('marketplacepartner/marketplacepartner')->isCustomerProducttemp($product_id['entity_id']);
    if($productowner['productid']!=""){
        $rowsocial=Mage::getModel('marketplaceprofile/marketplaceprofile')->getPartnerProfileById($productowner['userid']);
    }
?>

我正在使用Magento CE 1.7.0.2

我必须获得此产品的所有者ID

有什么想法吗?

4 个答案:

答案 0 :(得分:0)

尝试使用此代码

<?php

require_once 'app/Mage.php';

/*
* Initialize Magento. Older versions may require Mage::app() instead.
*/
Mage::init();

/*
* Get all unique order IDs for items with a particular SKU.
*/
$orderItems = Mage::getResourceModel('sales/order_item_collection')
->addFieldToFilter('sku', 'some-product-sku')
->toArray(array('order_id'));

$orderIds = array_unique(array_map(
function($orderItem) {
    return $orderItem['order_id'];
},
$orderItems['items']
));

/*
* Now get all unique customers from the orders of these items.
*/
$orderCollection = Mage::getResourceModel('sales/order_collection')
->addFieldToFilter('entity_id',   array('in'  => $orderIds))
->addFieldToFilter('customer_id', array('neq' => 'NULL'));
$orderCollection->getSelect()->group('customer_id');

foreach ($orderCollection as $order) {
$customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
var_dump($customer->getData());
}

参考此帖子Get users who has bought this product (MAGENTO)

答案 1 :(得分:0)

您可以使用Magento SQL查询获取产品的卖家ID:

(此查询适用于Webkul Marketplace扩展,但我认为您可以设法更改此查询以使用任何其他类似的扩展名)

/* Get the resource model */
$resource = Mage::getSingleton('core/resource');

/* Retrieve the read connection */
$readConnection = $resource->getConnection('core_read');

/* Get product id */
$productId = $this->getProduct()->getId();

/* Get table name */
$table = $resource->getTableName('marketplace/product');

/* Query for user id */
$query = 'SELECT userid FROM ' . $table . ' WHERE mageproductid = '. (int)$productId . ' LIMIT 1';

/* Execute the query and store the user id in $userid */
$userid = $readConnection->fetchOne($query);

答案 2 :(得分:0)

如果您使用的是市场扩展,可以试试这个

$_marketProduct=Mage::getModel('marketplace/product')->getCollection()->addFieldToFilter('adminassign',array('eq'=>1))->addFieldToFilter('mageproductid','product_id');
foreach($_marketProduct as $_mp){
            $_vendorId =$_mp->getuserid();             
            $_customerDetails = Mage::getModel('customer/customer')->load($_vendorId);
            print_r($_customerDetails);           }

并且不要忘记更改product_id

答案 3 :(得分:-1)

('marketplacepartner/marketplacepartner')更改为('marketplace/Userprofile')('marketplaceprofile/marketplaceprofile')('marketplace/Userprofile')

$product_id = $this->getProduct()->getId();
//echo $product_id; // It's displaying Product ID
$productowner=Mage::getModel('marketplace/Userprofile')>isCustomerProducttemp($product_id['entity_id']);
if($productowner['userid']!=""){
  $rowsocial=Mage::getModel('marketplace/Userprofile')->getPartnerProfileById($productowner['userid']);
}
$customer=Mage::getModel('customer/customer')->load($productowner['userid']);

echo $customer->getName();