0

I've been reviewing options for programmatically adding an item to a customer's quotation on the final stage of checkout (by selecting a tick box) which adds a simple product to the customer's order (a free product catalogue).

The code below works perfectly for adding the item within Magento, I'm simply having issues further down the line syncing this to another system due to missing fields in the sales_flat_order_item table.

Basically, when adding this free item in the admin by SKU rather than programmatically it assigns values to the following fields...

base_original_price tax_percent tax_amount base_tax_amount

There are a few others but these are the ones I believe I require. When adding by using the check box these fields are added as 'NULL'.

Below is the code currently in place to add the item to the quote as the order is placed...

public function addCatalogToOrder(Varien_Event_Observer $observer)
{
    $event = $observer->getEvent();
    $quote = $event->getQuote();
    $enabled = Mage::helper('catalogrequest')->isCatalogEnabled();
    $request = Mage::app()->getRequest()->getPost('add_catalog');

    if(!$request)
    {
        return false;
    }

    if(!$enabled)
    {
        return false;
    }

    if(!$quote->getId())
    {
        return false;
    }

    $sku = Mage::helper('catalogrequest')->getCatalogSku();
    $id = Mage::getModel('catalog/product')->getIdBySku($sku);

    $product = Mage::getModel('catalog/product')->load($id);
    $qty = 1;
    $quote = Mage::getSingleton('checkout/session')->getQuote();
    $quote->addProduct($product, $qty);
    $quote->save();
}

Any idea's to populate those fields would be greatly appreciated.

0

Although this may not solve other people's issues, this was the only solution I found after trying methods for collecting totals on the quotation etc. without avail so I changed the logic on my sync instead.

$catSku = Mage::helper('catalogrequest')->getCatalogSku();

            if($item->getSku() == $catSku) {}

Basically in the if statement I forced a vat_rate during this stage which worked, however if there is a better solution I'd be happy to review.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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