Skip to content

Instantly share code, notes, and snippets.

View yogeshdubey2006's full-sized avatar
🏠
Working from home

Yogesh Dubey yogeshdubey2006

🏠
Working from home
View GitHub Profile
<img src='<?php echo $this->getViewFileUrl('images/footer-logo.png'); ?>' alt="Demo">
<img src="{{view url="images/slide-bg.jpg"}}" alt="test" />
# https://magento.stackexchange.com/questions/93688/add-a-static-image-on-phtml-page-and-cms-blocks-magento2/93697
<img src='<?php echo $this->getViewFileUrl('Company_Module::images/image-icon.png'); ?>' alt="image-icon" width="30" height="25">
@yogeshdubey2006
yogeshdubey2006 / view.phtml
Created July 5, 2020 10:59
Magento 2 - How to get base, media, link url
<?php
//To get URL in magento2, you have to first create instance of \Magento\Framework\App\ObjectManager to get current store:
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); //instance of\Magento\Framework\App\ObjectManager
$storeManager = $_objectManager->get('Magento\Store\Model\StoreManagerInterface');
$currentStore = $storeManager->getStore();
// To get base URL
$baseUrl = $currentStore->getBaseUrl();
//Output: https://www.example.com/
@yogeshdubey2006
yogeshdubey2006 / bulk_filename_rename.ps1
Last active January 7, 2020 07:12
How to remove spaces from file names in bulk using Window platform
# Steps:
# Open a Powershell (Window).
# Go to the folder with the cd command (eg.: cd "path of your folder").
# e.g: cd C:\testFolder
# then type below command & replace .jpg file format with your file format.
# space is replace with underscore
# https://www.dropbox.com/s/4n1kdsfrohjt6tr/20200107_screenshot.jpg?dl=0
get-childitem *.jpg | foreach {rename-item $_ $_.name.replace(" ","_")}
@yogeshdubey2006
yogeshdubey2006 / cookie.js
Created October 17, 2019 10:18
Magento 2 - EU Cookie Law Notice custom code
@yogeshdubey2006
yogeshdubey2006 / delele-all-customers-and-orders.sql
Last active September 3, 2019 06:33
Magento 1 - delele all customers and orders through SQL
# SQL query delele all customers and orders from your Magento 1.* install.
# USE AT OWN RISK. ALWAY BACKUP YOUR DATABASE FIRST.
-- -----------------------------------------
-- delete all customers and customer logs --
-- -----------------------------------------
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE customer_address_entity;
@yogeshdubey2006
yogeshdubey2006 / simple.php
Created August 8, 2019 10:47
Magento 2 - showing error Required parameter 'theme_dir' was not passed while saving product in admin
# first method
### This error appears when you remove a template folder, which is still referenced in the database. The simplest way to fix it is, go to the database, and in table 'theme', find the theme name which does not exist in app/design/frontend/package.
### DELETE the reference to the missing theme from the table.
# Second method
### I have the same error Required parameter 'theme_dir' was not passed. I work with 2.1.0 from the beginning, not with updating. And I have one custom product attribute "style".
### The problem occurs when I try to save the new photo in the material. Without the image, the product saved normally.
### Fix with commenting the exception under the file:
### vendor/magento/framework/view/design/Fallbck/Rule/Simple.php
### It worked for me. But I think it's a hack.
@yogeshdubey2006
yogeshdubey2006 / attributes.phtml
Created July 18, 2019 12:36
Magento 2 - remove empty attributes "N/A" and "No"
<?php
# Path: \app\design\frontend\packageName\themeName\Magento_Catalog\templates\product\view\attributes.phtml
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
/**
* Product additional attributes template
*
@yogeshdubey2006
yogeshdubey2006 / news-subscribe.phtml
Created June 25, 2019 05:38
Magento - Newsletter second template
# app\design\frontend\packagename\default\template\newsletter\
<div style="background:#fff;" class="article right_section_col">
<div class="heading">
<h3><?php echo $this->__('Join Our Newsletter') ?></h3>
</div>
<form action="<?php echo $this->getUrl('newsletter/subscriber/new') ?>" method="post" id="newsletter_validate_detail_footer2">
<div style="margin-top:17px;" class="search-bar">
<input type="email" placeholder="Please Enter Emali..." maxlength="30" name="email" id="newsletter2" title="<?php echo $this->__('Sign up for our newsletter') ?>" class="sfield" />
<input type="submit" name="search" class="searchbutton" value="Submit" style="padding: 1px 0 0!important;" />
@yogeshdubey2006
yogeshdubey2006 / addtocart.phtml
Created June 9, 2019 03:00
Magento 2 - Speical price countdown
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
/** @var $block \Magento\Catalog\Block\Product\View */
?>
@yogeshdubey2006
yogeshdubey2006 / export.sql
Last active March 19, 2020 10:54
Export DB through command prompt
# I am exporting MySQL database from xampp through command prompt
# First of all, open command prompt.
# Import Database :- C:/xampp/mysql/bin/mysql -u root -p databasename < C:/test.sql (sql file name)
# Export Database :- C:/xampp/mysql/bin/mysqldump -u root -p databasename > C:/text.sql(sql file name)
# goto
C:\windows\system32>cd c:/xampp/mysql/bin
c:\xampp\mysql\bin>mysqldump -h localhost -u root -p dbname > export.sql