0

We currently use sweet tooth extension.

I am currently creating a quote in PHP which works as expected. My issue is applying an amount of Loyalty/Reward Points.

I know that the variable $loyalty_points_spent is working correctly, my problem is the following couple of lines do not apply the points to the quote.

if (isset($loyalty_points_spent) && !is_null($loyalty_points_spent)){
    $quote->setUseRewardPoints($loyalty_points_spent);
}

This is all of my code which currently creates a quote.

// initial vars
$productids = $order_details['products'];
$websiteId = $order_details['ids']['website_id'];
$store = $order_details['ids']['store_id'];
$loyalty_points_spent = $order_details['payment']['points_used'];
// Start New Sales Order Quote
$quote = Mage::getModel('sales/quote')->setStoreId($store);
// Set points
if (isset($loyalty_points_spent) && !is_null($loyalty_points_spent)){
    $quote->setUseRewardPoints($loyalty_points_spent);
}
// Set Sales Order Quote Currency
$quote->setBaseCurrencyCode($order_details['payment']['currency']);
$quote->setQuoteCurrencyCode($order_details['payment']['currency']);
$quote->setCurrency($order_details['payment']['currency']);
$customer = Mage::getModel('customer/customer')
        ->setWebsiteId($websiteId)
        ->loadByEmail($order_details['customer']['email']);
if ($customer->getId() == "") {
    $customer = Mage::getModel('customer/customer');
    $customer->setWebsiteId($websiteId)
            ->setStore($store)
            ->setFirstname($order_details['customer']['firstname'])
            ->setLastname($order_details['customer']['flastname'])
            ->setEmail($order_details['customer']['email']);
    $customer->save();
}
// Assign Customer To Sales Order Quote
$quote->assignCustomer($customer);
// Configure Notification
$quote->setSendCconfirmation(1);
// Set products
foreach ($productids as $id)
{
    $product_qty = $order_details['product_quantities'][$id];
    $product = Mage::getModel('catalog/product')->load($id);
    $quote->addProduct($product, new Varien_Object(array('qty' => $product_qty)));
}
// Set Sales Order Billing Address
$billingAddress = $quote->getBillingAddress()->addData(array(
    'customer_address_id' => $order_details['billing']['id'],
    'prefix' => $order_details['billing']['prefix'],
    'firstname' => $order_details['billing']['firstname'],
    'middlename' => $order_details['billing']['middlename'],
    'lastname' => $order_details['billing']['lastname'],
    'suffix' => $order_details['billing']['suffix'],
    'company' => '',
    'street' => $order_details['billing']['street'],
    'city' => $order_details['billing']['city'],
    'country_id' => $order_details['billing']['country'],
    'region' => 'UP',
    'postcode' => $order_details['billing']['postcode'],
    'telephone' => '78676789',
    'fax' => 'gghlhu',
    'vat_id' => '',
    'save_in_address_book' => 1
        ));
// Set Sales Order Shipping Address
$shippingAddress = $quote->getShippingAddress()->addData(array(
    'customer_address_id' => $order_details['billing']['id'],
    'prefix' => $order_details['shipping']['prefix'],
    'firstname' => $order_details['shipping']['firstname'],
    'middlename' => $order_details['shipping']['middlename'],
    'lastname' => $order_details['shipping']['lastname'],
    'suffix' => $order_details['shipping']['suffix'],
    'company' => '',
    'street' => $order_details['shipping']['street'],
    'city' => $order_details['shipping']['city'],
    'country_id' => $order_details['shipping']['country'],
    'region' => 'UP',
    'postcode' => $order_details['shipping']['postcode'],
    'telephone' => '78676789',
    'fax' => 'gghlhu',
    'vat_id' => '',
    'save_in_address_book' => 1
        ));
// Collect Rates and Set Shipping & Payment Method
$shippingAddress->setCollectShippingRates(true)
        ->collectTotals()
        ->collectShippingRates()
        ->setShippingMethod('royalmail_UK_CONFIRMED_ROYAL_MAIL_SIGNED_FOR_FIRST_CLASS_SMALL_PARCEL')
        ->setPaymentMethod($pmethod);
// Set Sales Order Payment
$quote->getPayment()->importData(array('method' => $pmethod));
// Collect Totals & Save Quote
$quote->collectTotals()->save();
return $quote;

1 Answer 1

0

I resolved the issue using the following:

// Get points used from order

$order->getPointsUsed($orderId);

// Set points used on quote and billingAddress

$quote->setPointsSpending($loyalty_points_used);
$billingAddress->setPointsSpending($loyalty_points_used);

// Remove points from user's account

$transfer = Mage::getModel('rewards/transfer');
$transfer->setId(null)
                ->setCurrencyId("1")
                ->setQuantity($points)
                ->setComments(Mage::getStoreConfig('rewards/transferComments/orderSpent'))
                ->setRuleId("1")
                ->setCustomerId($customerId)
                ->save();

Hopefully this helps anyone else trying to programatically use Sweet Tooth Loyalty Points

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.