cd /var/www/html && php bin/magento setup:upgrade && php bin/magento setup:static-content:deploy && chmod -R 0777 *
Wednesday, 19 October 2016
Thursday, 22 September 2016
How to get cart item remove or empty (truncate) in magento 2
Company name :- Sbr
Module name :- Checkout
File path :- /app/code/Sbr/Checkout/etc
============= File name events.xml =====================
<?xml version="1.0"?>
<!--
/**
* @author SB , SBR
* @package Sbr_Checkout
* @copyright Copyright (c) 2015 Sbr Limited (http://www.Sbr.co.nz)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="controller_action_predispatch_checkout_cart_add">
<observer name="beforecart"
instance="Sbr\Checkout\Observer\BeforeCart"/>
</event>
</config>
=================================================
============= File name module.xml =====================
<?xml version="1.0"?>
<!--
/**
* @author SB, Sbr
* @package
* @copyright Copyright (c) 2015 Sbr
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Sbr_Checkout" setup_version="2.0.4">
</module>
</config>
======================================================
============= File name BeforeCart.php =====================
File path :- /app/code/Sbr/Checkout/Observer
<?php
namespace Sbr\Checkout\Observer;
/*
ini_set("display_errors", "On");
error_reporting(E_ALL);
*/
use Magento\Framework\Event\ObserverInterface;
class BeforeCart implements ObserverInterface {
protected $cart;
public function __construct(
\Magento\Checkout\Model\Cart $cart
) {
$this->cart = $cart;
}
public function execute(\Magento\Framework\Event\Observer $observer) {
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $_objectManager->get('Magento\Store\Model\StoreManagerInterface');
$currentStore = $storeManager->getStore();
$currentStore_id = $currentStore->getId();
if($currentStore_id==1):
$count=count($this->cart->getItems());
if($count>=1){
foreach($this->cart->getItems() as $_item){
$sku=trim($_item['sku']);
if(($sku=='basic1')||($sku=='starter')||($sku=='professional')||($sku=='premium')){
$this->cart->truncate();
}
}
}
endif;
}
}
Module name :- Checkout
File path :- /app/code/Sbr/Checkout/etc
============= File name events.xml =====================
<?xml version="1.0"?>
<!--
/**
* @author SB , SBR
* @package Sbr_Checkout
* @copyright Copyright (c) 2015 Sbr Limited (http://www.Sbr.co.nz)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="controller_action_predispatch_checkout_cart_add">
<observer name="beforecart"
instance="Sbr\Checkout\Observer\BeforeCart"/>
</event>
</config>
=================================================
============= File name module.xml =====================
<?xml version="1.0"?>
<!--
/**
* @author SB, Sbr
* @package
* @copyright Copyright (c) 2015 Sbr
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Sbr_Checkout" setup_version="2.0.4">
</module>
</config>
======================================================
============= File name BeforeCart.php =====================
File path :- /app/code/Sbr/Checkout/Observer
<?php
namespace Sbr\Checkout\Observer;
/*
ini_set("display_errors", "On");
error_reporting(E_ALL);
*/
use Magento\Framework\Event\ObserverInterface;
class BeforeCart implements ObserverInterface {
protected $cart;
public function __construct(
\Magento\Checkout\Model\Cart $cart
) {
$this->cart = $cart;
}
public function execute(\Magento\Framework\Event\Observer $observer) {
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $_objectManager->get('Magento\Store\Model\StoreManagerInterface');
$currentStore = $storeManager->getStore();
$currentStore_id = $currentStore->getId();
if($currentStore_id==1):
$count=count($this->cart->getItems());
if($count>=1){
foreach($this->cart->getItems() as $_item){
$sku=trim($_item['sku']);
if(($sku=='basic1')||($sku=='starter')||($sku=='professional')||($sku=='premium')){
$this->cart->truncate();
}
}
}
endif;
}
}
=================================================================
==============File name registration.php ========================
File path:- app/code/Sbr/Checkout
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Sbr_Checkout',
__DIR__
);
====================================
How to get customer data from email id in magento 2
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$customer_email=$_REQUEST['list'];
///echo $customer_email;exit;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$url = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $url->get('\Magento\Store\Model\StoreManagerInterface');
$state = $objectManager->get('\Magento\Framework\App\State');
$state->setAreaCode('frontend');
$websiteId = $storeManager->getWebsite()->getWebsiteId();
// Get Store ID
$store = $storeManager->getStore();
$storeId = $store->getStoreId();
$customerFactory = $objectManager->get('\Magento\Customer\Model\CustomerFactory');
$customer=$customerFactory->create();
$customer->setWebsiteId($websiteId);
$customer->loadByEmail($customer_email);// load customer by email address
//echo $customer->getEntityId();
//$customer->load('1');// load customer by email address
$data= $customer->getData();
$customer_id=$data['entity_id'];
$objectManager = $bootstrap->getObjectManager();
$customer_email=$_REQUEST['list'];
///echo $customer_email;exit;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$url = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $url->get('\Magento\Store\Model\StoreManagerInterface');
$state = $objectManager->get('\Magento\Framework\App\State');
$state->setAreaCode('frontend');
$websiteId = $storeManager->getWebsite()->getWebsiteId();
// Get Store ID
$store = $storeManager->getStore();
$storeId = $store->getStoreId();
$customerFactory = $objectManager->get('\Magento\Customer\Model\CustomerFactory');
$customer=$customerFactory->create();
$customer->setWebsiteId($websiteId);
$customer->loadByEmail($customer_email);// load customer by email address
//echo $customer->getEntityId();
//$customer->load('1');// load customer by email address
$data= $customer->getData();
$customer_id=$data['entity_id'];
Thursday, 15 September 2016
How to get Category Id of current product in magento
$categoryIds = $_product->getCategoryIds();
if(count($categoryIds) ){
$firstCategoryId = $categoryIds[0];
$_category = Mage::getModel('catalog/category')->load($firstCategoryId);
echo $_category->getName();
echo $_category->getId();
}
if(count($categoryIds) ){
$firstCategoryId = $categoryIds[0];
$_category = Mage::getModel('catalog/category')->load($firstCategoryId);
echo $_category->getName();
echo $_category->getId();
}
Monday, 12 September 2016
Magento Select Query
$connectionWrite = Mage::getSingleton('core/resource')->getConnection('core_read');
$resource = Mage::getSingleton('core/resource');
$tableName = $resource->getTableName('marketplace_product');
$query = 'SELECT userid FROM ' . $tableName . ' WHERE mageproductid = '.(int)$product_Id ;
$userid = $connectionWrite->fetchOne($query);
$resource = Mage::getSingleton('core/resource');
$tableName = $resource->getTableName('marketplace_product');
$query = 'SELECT userid FROM ' . $tableName . ' WHERE mageproductid = '.(int)$product_Id ;
$userid = $connectionWrite->fetchOne($query);
Thursday, 4 August 2016
Thursday, 28 July 2016
mahemto cart use on set description
===Set Description===================================
app/code/core/Mage/Sales/Model/Quote.php
public function addProductAdvanced(
after this coding :-
$items[] = $item;
$item->setDescription($_customValue);
=========================================
app/design/frontend/rwd/nassaunationalcable/template/checkout/cart/item/default.phtml
$_item->getDescription();
app/code/core/Mage/Sales/Model/Quote.php
public function addProductAdvanced(
after this coding :-
$items[] = $item;
$item->setDescription($_customValue);
=========================================
app/design/frontend/rwd/nassaunationalcable/template/checkout/cart/item/default.phtml
$_item->getDescription();
Subscribe to:
Posts (Atom)