Posts

Get Customer Address with customer ID programmatically Magento2

<?php /** * * Copyright © 2015 Bluethinkcommerce. All rights reserved. */ namespace Module\Api\Controller\Index; class Customeraddress extends \Magento\Framework\App\Action\Action { /** * @var \Magento\Framework\App\Cache\TypeListInterface */ protected $_cacheTypeList ; /** * @var \Magento\Framework\App\Cache\StateInterface */ protected $_cacheState ; /** * @var \Magento\Framework\App\Cache\Frontend\Pool */ protected $_cacheFrontendPool ; /** * @var \Magento\Framework\View\Result\PageFactory */ protected $resultPageFactory ; /** * @param Action\Context $context * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList * @param \Magento\Framework\App\Cache\StateInterface $cacheState * @param \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory */ ...

Magento2 Commands

These are Some Magento2 Commands  <?php //Magento Commands// ( 1 ) sudo chmod -R 777 var ( 2 ) sudo chmod -R 777 pub ( 3 ) rm -Rf var /generation ( 4 ) sudo chmod -R 777 / var /www/html/magento2 ( for permission to folder) //////////////////Setup Upgrade Using Command Line php bin/magento setup:upgrade /////////////////////If you don’t want to remove pub/static files while installing/updating database then use following command. php bin/magento setup:upgrade --keep-generated //////////////////Cache Clean Using Command Line php bin/magento cache:clean //////////////////Cache Flush Using Command Line php bin/magento cache: flush //////////////////View cache status Using Command Line php bin/magento cache:status ///////////////////////Enable Cache Using Command Line php bin/magento cache:enable [cache_type] //////////////////////Disable Cache Using Command Line php bin/magento cache:disable [cache_type] ////////////////////////Static...

Get Swatch Text Product id of Configurable Product in Detail Page through Jquery Magento2

Add This Script in Detail Page You will get id of selected Product <script type= "text/javascript" > require([ 'jquery' ], function (jQuery){ jQuery( 'body' ).on( 'click' , '.swatch-option' , function (e) { var swatchid = jQuery( '.swatch-attribute' ).attr( 'option-selected' ); if (swatchid) { selpro(); } }); }); function selpro () { var selected_options = {}; jQuery( 'div.swatch-attribute' ).each( function (k,v){ var attribute_id = jQuery(v).attr( 'attribute-id' ); var option_selected = jQuery(v).attr( 'option-selected' ); console.log(attribute_id, option_selected); if (!attribute_id || !option_selected){ return ;} if (attribute_id || option_selected){ selected_options[attribute_id] = option_selected; } }); console.log(sel...

Add Product Rating and Reviews in Magento2

Add This Code in Controller Or Use in Phtml <?php namespace Custom \Module\Controller\Index; use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; class Productrating extends \Magento\Framework\App\Action\Action { public function __construct ( Context $context , \Magento\Review\Model\ReviewFactory $reviewFactory , \Magento\Review\Model\RatingFactory $ratingFactory , \Magento\Store\Model\StoreManagerInterface $storeManager ) { parent :: __construct ( $context ); $this -> _reviewFactory = $reviewFactory ; $this -> _ratingFactory = $ratingFactory ; $this -> _storeManager = $storeManager ; } public function execute () { $productid = 201 ; //product id you set accordingly $reviewdata [ 'ratings' ][ 1 ] = 5 ; //Rating First $reviewdata [ 'ratings' ][ 2 ] = 4 ; //Rating Second $r...

Change Customer Password Programmatically Magento 2

Add This Code In Controller <?php namespace Custom\Module\Controller\Index; use Magento\Framework\Encryption\EncryptorInterface as Encryptor; class Customerpassword extends \Magento\Framework\App\Action\Action { /** * @var \Magento\Framework\App\Cache\TypeListInterface */ protected $_cacheTypeList ; /** * @var \Magento\Framework\App\Cache\StateInterface */ protected $_cacheState ; /** * @var \Magento\Framework\App\Cache\Frontend\Pool */ protected $_cacheFrontendPool ; /** * @var \Magento\Framework\View\Result\PageFactory */ protected $resultPageFactory ; /** * @param Action\Context $context * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList * @param \Magento\Framework\App\Cache\StateInterface $cacheState * @param \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool * @param \Magento\Framework\View\Result\PageFacto...

programmaticlly Create Order in Magento2 with custom options in order

<?php namespace Custom\Api\Controller\Index; use Magento\Framework\App\Action\Context; use Magento\Framework\View\Result\PageFactory; class Createbooking extends \Magento\Framework\App\Action\Action { /** * @var \Magento\Framework\App\Cache\TypeListInterface */ protected $_cacheTypeList ; /** * @var \Magento\Framework\App\Cache\StateInterface */ protected $_cacheState ; /** * @var \Magento\Framework\App\Cache\Frontend\Pool */ protected $_cacheFrontendPool ; /** * @var \Magento\Framework\View\Result\PageFactory */ protected $resultPageFactory ; /** * @param Action\Context $context * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList * @param \Magento\Framework\App\Cache\StateInterface $cacheState * @param \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool * @param \Magento\Framework\View\Result\PageFactory $resultPageFact...

Get Three Level Category and Subcategories through Category id in Root file Magento2

Create a File in Root of Magento2 <?php use Magento \ Framework \ App \ Bootstrap ; require __DIR__ . '/app/bootstrap.php' ; $params = $_SERVER ; $bootstrap = Bootstrap : : create ( BP , $params ) ; $obj = $bootstrap - > getObjectManager ( ) ; $state = $obj - > get ( 'Magento\Framework\App\State' ) ; $state - > setAreaCode ( 'frontend' ) ;        /*$params = (array) json_decode(file_get_contents('php://input'), TRUE);     print_r($params); ////////// Get Data From Postman Api/////////     $catid=$params['caterory'];     echo "string+++++".$catid;*/           /*echo"<pre>++";     print_r($_GET['caterory']);*/ //// Get Data Through URL////////      $catid = $_GET [ 'cateroryid' ] ;      $obj...