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 / 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".

@gelanivishal
gelanivishal / in_cms_content.txt
Created January 6, 2017 03:12
Display Static Block in Phtml file & CMS page
{{block class="Magento\\Cms\\Block\\Block" block_id="block_identifier"}}
Find the PHP binary and php.ini path
To display the path to your PHP binary, enter
which php
A sample result follows:
/usr/bin/php
Create the cron job
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$reviewFactory = $objectManager->create('Magento\Review\Model\Review');
$storeId = $this->_storeManager->getStore()->getId();
$reviewFactory->getEntitySummary($product, $storeId);
$ratingSummary = $product->getRatingSummary()->getRatingSummary();