Monday 10 July 2017

Magento get All search terms using programatically

<?php
//echo "hiii";die("here");
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once(__DIR__ . '/app/Mage.php');
Mage::app();
umask(0);
$searchCollection=Mage::getModel('catalogsearch/query')->getCollection();
//echo "<pre>";print_r($searchCollection->getData());die("here");
$searchData = $searchCollection->getData();
foreach($searchData as $terms){
echo $terms['query_text'];
echo "<br />";
}
die("here");
?>

Friday 7 July 2017

Magento2 Upgrade from 2.0.x-2.1.x

In composer.json change this line
"magento/product-community-edition": "2.0.0",
Also you should change the line 5 as well "version": "2.0.0", to keep it in sync.
to whatever version you want, and then run:
composer update
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
if any Authenication required give the public keys and private keys 
as a username and password of Your magento.com account login

Magento 9767 patch issue in checkout page customer registration

Saturday 1 April 2017

Add Customer Address for existing customer using CSV

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
use Magento\Framework\App\Bootstrap;
include('app/bootstrap.php');
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$url = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $url->get('\Magento\Store\Model\StoreManagerInterface');
$websiteId = $storeManager->getWebsite()->getWebsiteId();
$state = $objectManager->get('\Magento\Framework\App\State');
$state->setAreaCode('frontend');
if(($handle = fopen("customers.csv", "r")) !== FALSE) {
while (( $csvFile = fgetcsv($handle, 1000, ",")) !== FALSE) {
//echo $csvFile[0];die;
$customerFactory = $objectManager->get('\Magento\Customer\Model\CustomerFactory');
$customer=$customerFactory->create();
$customer->setWebsiteId($websiteId);
$customer->loadByEmail($csvFile[0]);
$data= $customer->getData();
//echo "<pre>";print_r($data);die('Ram');
$customer_id=$data['entity_id'];
try{
$addresss = $objectManager->get('\Magento\Customer\Model\AddressFactory');
$address = $addresss->create();
$address->setCustomerId($customer_id)
->setFirstname($csvFile[6])
->setLastname($csvFile[9])
->setCountryId($csvFile[17])
->setPostcode($csvFile[19])
->setCity($csvFile[15])
->setTelephone($csvFile[22])
->setFax($csvFile[18])
->setCompany($csvFile[16])
->setStreet($csvFile[21])
->setIsDefaultBilling('1')
->setIsDefaultShipping('1')
->setSaveInAddressBook('1');
$address->save();
echo $customer_id . "Address is Added Successfully";
echo '<br/>';
}
catch(Exception $e){
echo $e->getMessage();
}
}
}
else{
echo $customer_id . "Address is not added Successfully";
}

Product Collection with out of stock and In Stock in Magento 2

Product collection with out of stock and In stock. use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; $collection = $th...