Skip to content

Instantly share code, notes, and snippets.

View gelanivishal's full-sized avatar
🎯
Focusing

Vishal Gelani gelanivishal

🎯
Focusing
View GitHub Profile
@gelanivishal
gelanivishal / print_transcational_email.md
Created February 18, 2017 15:05
Magento 2 print transcational email before mail send

Open following file :

{root}/vendor/magento/framework/Mail/Template/TransportBuilder.php

and find prepareMessage() function at line number 265

Just echo $body and exit the exceution of code.

@gelanivishal
gelanivishal / prefix.php
Created February 10, 2017 16:27
Get table prefix
<?php
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$deploymentConfig = $obj->get('Magento\Framework\App\DeploymentConfig');
$tablePrefix = $deploymentConfig->get('db/table_prefix');
@gelanivishal
gelanivishal / jquery-ver.js
Created February 10, 2017 16:26
Retrieve jQuery Version
// Type one of the next lines and you will obtain jQuery version:
console.log(jQuery.fn.jquery);
// OR
console.log(jQuery().jquery);
@gelanivishal
gelanivishal / baseimage.php
Created February 10, 2017 16:25
Base image not assigned product list
<?php
require_once ( "app/Mage.php" );
Mage::app();
umask(0);
//echo Mage::getBaseUrl();
$url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
//exit;
$_productCollection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSort('created_at', 'DESC')
@gelanivishal
gelanivishal / assign_baseimage.php
Created February 10, 2017 16:25
Assign first media image as base image.
<?php
include 'app/Mage.php';
Mage::app();
$productId = 4299;
//load the product
$product = Mage::getModel('catalog/product')->load($productId);
//get all images
$mediaGallery = $product->getMediaGallery();
//if there are images
@gelanivishal
gelanivishal / clean_cache.php
Last active February 21, 2017 01:37
M1 - Clear cache programatically
<?php
//increase execution time
ini_set('max_execution_time', 900); //900 seconds = 15 minutes
//require Magento
require_once 'app/Mage.php';
$app = Mage::app('admin');
umask(0);
//enable Error Reporting
@gelanivishal
gelanivishal / cart.md
Created January 16, 2017 15:37
Get all shopping cart items, subtotal, grand total, billing & shipping address

Get all items information in cart

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cart = $objectManager->get('\Magento\Checkout\Model\Cart'); 

// retrieve quote items collection
$itemsCollection = $cart->getQuote()->getItemsCollection();

// get array of all items what can be display directly
$itemsVisible = $cart->getQuote()->getAllVisibleItems();
@gelanivishal
gelanivishal / new_gist_file_0.md
Last active February 21, 2017 01:38
Add new tab in Product detail page

New tab in product detail page is very easy task with product attribute. Use below steps and check it out.

  • Step 1. Create Product Attribute “video”.

  • Step 2. Create file catalog_product_view.xml in the app/design/frontend/{vender name}/{theme name}/Magento_Catalog/layout

In the file write the below code:

@gelanivishal
gelanivishal / admin_reset.md
Last active February 21, 2017 01:38
Reset Admin Password + Magento

To login into magento admin, using only ftp access is a little tricky. Through FTP open the class Mage_Admin_Model_User located at

app\code\core\Mage\Admin\Model\User.php

Next find the

$this->loadByUsername($username);
@gelanivishal
gelanivishal / add_qty_dropdown.md
Last active February 21, 2017 01:38
How To Add Quantity drop down on Magento Product Page

Step-> 1 :: Go to app/design/frontend/base/default/template/catalog/product/view/addtocart.phtml

In the addtocart.phtml file find the following code(around line 33)

<input name="qty" type="text" class="input-text qty" id="qty" maxlength="12" value="<?php echo $this->getMinimalQty($_product) ?>" />

Step-> 2 :: Replace with this code:

This code shows the "Available Qty for Product".