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
@yogeshdubey2006
yogeshdubey2006 / change-categories-magento-anchor-set-yes-1-click.php
Last active December 29, 2018 12:15
Magento 1 - Often times there is a need to change all Magento Categories from their default setting of 'Is Anchor = No' to 'Is Anchor=Yes'.
<?php
/* Making the change to an Anchor Category activates the Layered Navigation, also known as filtered navigation. If you have multiple Categories this can be a time-consuming task to do manually. The better way is to use the following code to run through and change all Categories to Anchor in just 1 Click. *It is always a good idea before making changes to the database that you first create a database backup. This has become very quick and easy using the Magento Admin. *To make your backup using Magento Admin, navigate to [System] [Tools] [Backups]. *once there select the option Database Backup (don’t worry it doesn’t take long). Now that you are ready, create a new file called category-achor-yes.php and place it in the root of your Magento install (where your index.php file is).*/
error_reporting(E_ALL);
ini_set('display_errors', '1');
// Load Up Magento Core
define('MAGENTO', realpath(''));
require_once(MAGENTO . '/app/Mage.php');
@yogeshdubey2006
yogeshdubey2006 / catalog_product_view.xml
Last active December 29, 2018 11:45
Magento 2 Remove review block from product page
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="reviews.tab" remove="true" />
<referenceBlock name="product.review.form" remove="true" />
<referenceBlock name="product.info.review" remove="true" />
</body>
</page>
@yogeshdubey2006
yogeshdubey2006 / useful-php-code.php
Last active December 29, 2018 11:10
Useful PHP code
<?php
// To split the date and time from datetime value
$date = strtotime('10/29/2018 10:54:15 PM');
$dat = date('m/d/y', $date);
$tme = date('H:m:s A',$date);
?>
@yogeshdubey2006
yogeshdubey2006 / useful-html-code.html
Created December 29, 2018 11:23
Useful Html Code
<!-- To prevent cut copy paste in text field -->
<input type="text" onselectstart="return false" onpaste="return false;" onCopy="return false" onCut="return false" onDrag="return false" onDrop="return false" autocomplete=off />
@yogeshdubey2006
yogeshdubey2006 / magento2_reset_password.sql
Created December 29, 2018 11:26
Magento 2 Reset Customer Password through SQL
UPDATE `customer_entity`
SET `password_hash` = CONCAT(SHA2('xxxxxxxxYOURPASSWORD', 256), ':xxxxxxxx:1') // change YOURPASSWORD to your password to reset
WHERE `entity_id` = 199 and `email`="[email protected]";
@yogeshdubey2006
yogeshdubey2006 / magento2_commands_shortcut.sh
Last active August 30, 2019 18:28
Magento 2 Command Shortcuts
## For deployment correct order
php bin/magento deploy:mode:set production
php bin/magento cache:clean
php bin/magento cache:flush
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy
## if developer mode is enabled
php bin/magento setup:static-content:deploy -f
@yogeshdubey2006
yogeshdubey2006 / magento-clear-log.sql
Created December 29, 2018 11:52
Magento 1 - Clearing the log files
SET foreign_key_checks = 0;
truncate adminnotification_inbox;
truncate log_customer;
truncate log_quote;
truncate log_summary;
truncate log_summary_type;
truncate log_url;
truncate log_url_info;
truncate log_visitor;
truncate log_visitor_info;
@yogeshdubey2006
yogeshdubey2006 / customer_reset_password.sql
Created December 29, 2018 12:12
Magento 1 - Reset all customer password
UPDATE `customer_entity_varchar` caev
JOIN `customer_entity` ce ON ce.entity_id=caev.entity_id
JOIN `eav_attribute` ea ON ea.entity_type_id=ce.entity_type_id AND caev.attribute_id=ea.attribute_id
SET caev.value=MD5('admin123')
WHERE ea.attribute_code='password_hash';
@yogeshdubey2006
yogeshdubey2006 / get-product-id.php
Created December 29, 2018 12:25
Magento 2 get product id to my custom module
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Framework\Registry')->registry('current_product'); //get current product
echo $product->getId();
echo $product->getName();
?>
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productid = $this->getRequest()->getParam('id');
@yogeshdubey2006
yogeshdubey2006 / useful-magento-tricks.txt
Last active February 28, 2019 06:29
Magento 2 useful tricks
-- Call static block in phtml file
<?php $this->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('static_block_identifier')->toHtml(); ?>
-- In xml layout file
<block class="Magento\Framework\View\Element\Template" name="test_file" template="Magento_Theme::html/test.phtml"/>
-- In cms blocks and cms pages
{{block class="Magento\Framework\View\Element\Template" name="test_file" template="Magento_Theme::html/test.phtml"}}