Monday 25 March 2019

Programmatically assign customer to a quote in magento

$customer = Mage::getModel('customer/customer')->load($userId);

$quote = Mage::getModel('sales/quote')->load($quoteId);
$quote->setCustomer($customer);
$quote->save();

How to copy one quote (only cart items) to other quote (only items ) in magento

$quoteA = Mage::getModel('sales/quote')->load($quoteId);
$quoteB = Mage::getModel('sales/quote')->load($userQuoteId);
$quoteB->merge($quoteA);
$quoteA->delete();
$quoteA->collectTotals()->save();
$quoteB->collectTotals()->save();

Monday 18 March 2019

How do I add to wishlist programatically in magento 1.9?

$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customerId, true);
$product = Mage::getModel('catalog/product')->load($productId);

$buyRequest = new Varien_Object(array()); // any possible options that are configurable and you want to save with the product

$result = $wishlist->addNewItem($product, $buyRequest);
$wishlist->save();

Tuesday 5 March 2019

How to get (cart) items programatically shows duplicate SKUs for both the configurable and simple product in magento


As you have using getAllItems() then on for loop you need to check is it has parent item $item->getParentItemId().

foreach ($cart->getAllItems() as $item) {
    / * add this */
    if ($item->getParentItemId()) {
        continue;
    }
........
}

Saturday 2 March 2019

Check the customer password field Magento 1.9

    $email='test@gmail.com';
    $customer =Mage::getModel('customer/customer')
    ->setWebsiteId(Mage::app()->getStore()
    ->getWebsiteId())
    ->loadByEmail($email);
    $hash= $customer->getPasswordHash();

    Mage::helper('core')->validateHash($currentpassword, $hash);