Monday, 25 March 2019

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);

Thursday, 14 February 2019

Get product from save event observer - Magento 2

Get product from save event observer - Magento 2

If you want to $productobj after saving product from backend then you can easily use catalog_product_save_after event.
I am assuming that you already know how to create a module in M2.
Put this events.xml in below path
app\code\YOUR_NAMESPACE\YOURMODULE\etc\adminhtml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="catalog_product_save_after">
        <observer name="test_name" instance="YOUR_NAMESPACE\YOUR_MODULENAME\Observer\Productsaveafter" />
    </event>
</config>

And put your Productsaveafter.php in below path
app\code\YOUR_NAMESPACE\YOURMODULE\Observer\


<?php

namespace YOURNAMESPACE\YOURMODULENAME\Observer;

use Magento\Framework\Event\ObserverInterface;

class Productsaveafter implements ObserverInterface
{   
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $_product = $observer->getProduct();  // you will get product object
        $_sku=$_product->getSku(); // for sku

    }  
}

Tuesday, 12 February 2019

How to search for product by name or sku with PageSize and CurPage programatically magento 1.9?

How to search for product by name or sku with PageSize and CurPage programatically magento 1.9?
$products = Mage::getModel('catalog/product')
                    ->getCollection()
                    ->addAttributeToFilter(
                        array(
                            array('attribute' => 'sku', 'like' => '%'.$search.'%'),
                            array('attribute' => 'name', 'like' => '%'.$search.'%')
                        )
                    )
                    ->setPageSize(10)->setCurPage(1)->load();

Tuesday, 15 January 2019

How to get instagram feed in custom page in magento

<?php
$fields = array(
'client_id' => "bdb4fd62e6e24f938fb7d124acf80187",
'client_secret' => "1cca64ded0e046118b311fdc001bb52c",
'grant_type' => "authorization_code",
'redirect_uri' => "http://wgi-mobile-dev-949798541.ap-south-1.elb.amazonaws.com/insta.php",
//'code' => $_GET['code'],
);
//1484074220.1677ed0.af32987ae8984bb59d9803afabc83e65
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.instagram.com/v1/users/self/media/recent/?access_token=1484074220.1677ed0.af32987ae8984bb59d9803afabc83e65');
curl_setopt($ch, CURLOPT_POST, false);
//curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$posts = curl_exec($ch);
curl_close($ch);
$posts = json_decode($posts);

if ($posts) {
foreach ($posts->data as $dat) {
echo '<img src="' . $dat->images->standard_resolution->url . '" style="width:250px;height:200px;">';
}
}
?>

instagram access token generator :- https://instagram.pixelunion.net/