Skip to content

Instantly share code, notes, and snippets.

View gelanivishal's full-sized avatar
🎯
Focusing

Vishal Gelani gelanivishal

🎯
Focusing
View GitHub Profile

Magento 2 Tips, Tricks and Snippets

Infos About Store##

inject \Magento\Store\Model\StoreManagerInterface $storeManage
$this->storeManager = $storeManager;

Get Store id
$id = $this->storeManager->getStore()->getId();

Magento 2(Customer) Tips, Tricks and Snippets

Add Tab in Customer Dashboard (Frontside)
<?xml version="1.0" encoding="UTF-8"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="customer_account_navigation">
            <block class="Magento\Framework\View\Element\Html\Link\Current" ifconfig="helpdesk/frontend/is_active" name="customer-account-navigation-helpdesk-link">
                <arguments>
@gelanivishal
gelanivishal / 0_reuse_code.js
Created November 26, 2016 15:41
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@gelanivishal
gelanivishal / clear_cache.php
Last active February 21, 2017 01:42
Clear cache/reindex
<?php
include 'app/Mage.php';
Mage::app();
// clear cache
Mage::app()->removeCache('catalog_rules_dirty');
// reindex prices
Mage::getModel('index/process')->load(2)->reindexEverything();
/*
@gelanivishal
gelanivishal / functions.php
Created November 28, 2016 06:59
Hook while save page and create new post and append function.php
<?php
add_action( 'save_post', 'my_save_post_function', 10, 3 );
function my_save_post_function( $post_ID, $post, $update ) {
$fields=$_POST['fields'];
if(isset($_POST['fields']) && $_POST['fields']!=""){
$fields= implode(array_values($fields));
// unhook this function so it doesn't loop infinitely
remove_action('save_post', 'my_save_post_function');
@gelanivishal
gelanivishal / import.sql
Created November 28, 2016 07:17
Import Export command for Db via terminal
// Import Database in WAMP:
mysql -u username -p database_name < your_sql_file.sql
// Export Database in WAMP:
mysqldump -u username -p database_name > db_file.sql
mysqldump -u db_username -p --compress --disable-keys --quick db_name | gzip > db.sql.gz
@gelanivishal
gelanivishal / get_product_stock.php
Created November 29, 2016 16:11
Get product stock quantity in magento
<?php
$products = Mage::getModel('catalog/product')
->getCollection()
//->addAttributeToSelect('*')
->addAttributeToSelect(array('name', 'thumbnail', 'weight' ,'price','description'))
->joinField('qty',
'cataloginventory/stock_item',
'qty',
'product_id=entity_id',
@gelanivishal
gelanivishal / configurable.php
Last active February 21, 2017 01:42
Create configurable and custom option simple product for magmi from Wordpress woo commerce.
<?php
print '<pre>';
$file = fopen("export_product-2016_11_29-06_05_42-30936353.csv","r");
$count = 0;
$varientProduct = array();
$variableProduct = array();
$simpleProduct = array();
$without_Parent_Id = array();
$productArrays = array();
@gelanivishal
gelanivishal / copy-products.php
Created December 1, 2016 06:56
MAGENTO: COPY PRODUCTS FROM ONE CATEGORY TO ANOTHER CATEGORY
<?php
require_once ( "app/Mage.php" );
umask(0);
// Initialize Magento
Mage::app();
$category = Mage::getModel('catalog/category');
$category->load('24'); // Category id you want to copy
$collection = $category->getProductCollection();