1

ゲストとして商品を購入されたお客様の名前とメールアドレスを取得できるようにしたいと思います。誰かがそうすることに運がありましたか?

クーポンコードを使用した顧客の名前を取得する方法についての投稿をいくつか見ましたが、非顧客については何もありません!

どうもありがとうございました!

-ジェフ

4

2 に答える 2

3

これは機能するはずです:

 $orderCollection = Mage::getModel('sales/order')->getCollection()
        ->addAttributeToSelect('customer_firstname')
        ->addAttributeToSelect('customer_lastname')
        ->addAttributeToSelect('customer_email')
        ->addAttributeToSelect('customer_group_id')
        ->addAttributeToFilter('customer_group_id', Mage_Customer_Model_Group::NOT_LOGGED_IN_ID)
 ;

次に、コレクションを反復処理することで値にアクセスできます...

foreach($orderCollection as $order) {
    $customerFirstname = $order->getData('customer_firstname');
    $customerLastname  = $order->getData('customer_lastname');
    $customerEmail     = $order->getData('customer_email');

    //Do what you want with the values here
}

編集:

上記のコードは、質問の最初の段落に答えます。2番目の段落は、あなたが何か違うものを探していることを示唆しています。特定のクーポンコードを使用したゲスト顧客をお探しですか?その場合は、次のようにコレクションをロードする必要があります。

$orderCollection = Mage::getModel('sales/order')->getCollection()
    ->addAttributeToSelect('customer_firstname')
    ->addAttributeToSelect('customer_lastname')
    ->addAttributeToSelect('customer_email')
    ->addAttributeToSelect('customer_group_id')
    ->addAttributeToSelect('coupon_code')
    ->addAttributeToFilter('customer_group_id', Mage_Customer_Model_Group::NOT_LOGGED_IN_ID)
    ->addAttributeToFilter('coupon_code', 'your_awesome_coupon_code')
;
于 2012-06-21T19:06:14.763 に答える
0

Drewは、別の同様の投稿で、既存の顧客の名前と電子メールのSQLステートメントを私にくれました。登録ユーザーとゲストを含むすべての注文を取得するには、次のSQLを使用できます。

SELECT `customer_firstname`, `customer_lastname`, `customer_email` FROM `sales_flat_order` WHERE  `coupon_code` = 'your_awesome_coupon_code' 

チャームのように働いた!'salesrule_coupon'をダブルチェックすると、SQLで返される行は、クーポンが使用された回数と一致します。

Drewの回答は正しいとマークしたままにしておきます。これは、Magentoで行う方がおそらく良いからです。SQLをお探しの方は、こちらをご利用ください。

登録ユーザー向けのSQLステートメントはここにあります:特定のクーポンコードがmagentoで使用されるたびに、完全な注文の詳細を確認するにはどうすればよいですか?

于 2012-07-10T18:52:53.520 に答える