سؤال

I have to implement some feedback customer code for getting enroled in their store database. the code is :

try {
$Client = new TrustedShop('key'); 
$Client->SetEmail();
$Client->AddProduct('Name of first purchased product');
$Client->AddProduct('Name of second purchased product');
$Client->Send();

Nice and simple.

The logic is that after some days, they will send my customer a feedback for asking about their shopping experience on the store.

I have currently embeded it into /public_html/app/design/frontend/base/default/template/persistent/checkout/onepage/billing.phtml

with the $Client->SetEmail($this->getAddress()->getEmail());

No problems here, but (and a big but :) ) how can i retrive the customer's ordered sku in billing phtml? And if the ordered contains 2 or 10 skus how can i send them to my partner ?

Is this the corect path to implement the code, or there is a better location in magento where i can retrive both the customer email and the ordered skus ?

P.S. Sorry if this is a stupidly simplistic question, newbie on the throttle here :)

هل كانت مفيدة؟

المحلول

EDIT:

the "dirty hack" solution:

At the billing.phtml the order is not yet placed, the customer can step back and quit shopping. It is not the good point to insert the logic. Instead, use the checkout/success.phtml template for the hack. You can do the following there:

<?php 
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
Mage::log($order->getCustomerEmail());
Mage::log($order->getCustomerFirstname());
Mage::log($order->getCustomerLastname());
foreach ($order->getAllVisibleItems() as $item) {
Mage::log($item->getSku());
};
?>

And that's it, you have all the data to implement the custom logic.

The RECOMMENDED solution starts here:

As i understand, you will have to send the name or SKU of ordered products an the customer's email to an external client. Magento has an event-driven architecture, so in issues like this it is much better to create an Observer to catch an event. (link to "how to create Observer") The event in your case is "sales_order_place_after". For this you need in your module's config eg. app/code/local/YOUR/MODULE/etc/config.xml:

<events>
    <sales_order_place_after>
        <observers>
            <any_unique_name_of_your_observer>
                <type>singleton</type>
                <class>yourclass/observer</class>
                <method>sendOrderInfo</method>
            </any_unique_name_of_your_observer>
        </observers>
    </sales_order_place_after>
</events>

And in you Observer, which is app/code/local/YOUR/MODULE/Model/Observer.php:

class YOUR_MODULE_Model_Observer extends Mage_Core_Model_Observer
{
public function sendOrderInfo($observer)
{
#get the order
$order = $observer->getEvent()->getOrder();

Mage::log($order->getBillingAddress());
Mage::log($order->getShippingAddress())
Mage::log($order->getCustomerEmail());
Mage::log($order->getCustomerFirstname());
Mage::log($order->getCustomerLastname());
foreach ($order->getAllVisibleItems() as $item) {
    $sku = $item->getSku();
...

This is an example how you can retrieve the data you need, and then you can implement your custom logic inside the method of the Observer.

EDIT: a more detailed example to get the sku of ordered items

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top