3

Is it possible to add/update a customers cart from admin?

        $productId = 700;

        $storeId = Mage::app()->getStore()->getId();

        $product = Mage::getModel('catalog/product')
                        ->setStoreId($storeId)
                        ->load($productId);


        $qty = 1;
        $cart = Mage::getModel('sales/quote');


        $cart->setStore(Mage::app()->getStore())->loadByCustomer($customer->getId());

        if (!$cart->getId())
        {
            $cart->assignCustomer($customer);
            $cart->save();
        }

        $info = new Varien_Object(array(
                            'product_id' => $product->getId(),
                            'qty' => $qty
                        ));

        $cart->addProduct($product, $info );

        $cart->collectTotals()->save();

This is writing an entry into the sales_flat_quote table but it is not showing up in the customers cart. I am doing something wrong or missing something.

5

Yes it's possible.
Find the customer in the backend, click on edit.
You should see a tab on the left called shopping cart. You would expect that it should work from there. But it doesn't. Or at least I didn't find a way to make it work.

But here is how I did.
Click on the 'Create order' from the customer edit screen.
Select a store view to associate the order with.
Then add to the order the products you want to put in the cart.
After adding them, you will see for each line a column named Action. Select from the dropdown for each product "Move to shopping cart".
Then hit "Update items and qty's".
That's it.

I know it seams like a strange process, but if you need it badly you can use it.

| improve this answer | |
  • can you point me in the right direction where this logic is located. I wish to replicate this logic in a custom module, because I need to interact with a 3rd party datasource. – user9252 Aug 4 '14 at 15:04
  • see Mage_Adminhtml_Sales_Order_CreateController::_processActionData specially the section that starts with $moveItemId = (int) $this->getRequest()->getPost('move_item'); – Marius Aug 4 '14 at 15:08
  • I have updated my post with code for my custom module. Can you have a look to see if I doing something wrong? – user9252 Aug 5 '14 at 13:33

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.