Skip to content

Instantly share code, notes, and snippets.

View magento-code-snippets.md

Magento Code Snippets

##DB Dump n98 magerun command no hangup

nohup ./n98-magerun.phar db:dump --compression="gzip" labdz &
#dev dump without useless info:
nohup ./n98-magerun.phar db:dump --compression="gzip" --strip="@development" labdz &

Image Bash Script Downloader Generator Folder Gallery and Main

@mokanfar
mokanfar / filter_unique_rows_script.sh
Last active Oct 23, 2018
Matched Rows, Unique Rows Merge Filter Bash Scripts for CSV files
View filter_unique_rows_script.sh
#!/usr/bin/env bash
echo "filename 1 (file that has more rows):"
read file1
echo "filename 2:"
read file2
echo "common field name:"
read fieldname
#echo "file1: ${file1}.csv file2: ${file2}.csv common field name: ${fieldname}"
if [ -f $PWD/temp.db ]; then
View get_final_price_of_skus_for_certain_customer_group.php
<?php
require_once 'app/Mage.php';
Mage::app();
//to overwrite limit but you need first to increase your memory limit
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*') // select all attributes
->setPageSize(5000) // limit number of results returned
->setCurPage(1); // set the offset (useful for pagination)
// we iterate through the list of products to get attribute values
@mokanfar
mokanfar / list_all_gallery_images_magento_product_by_sku.php
Last active Aug 24, 2018
get all images associated with an array of product sku's programatically in Magento [first one is base/main image]
View list_all_gallery_images_magento_product_by_sku.php
@mokanfar
mokanfar / bulk_set_array_of_skus_attribute_programatically_in_magento.php
Last active Jul 18, 2018
Magento update from list of skus an attribute programatically
View bulk_set_array_of_skus_attribute_programatically_in_magento.php
<?php
require_once 'app/Mage.php';
Mage::app();
$skus = array("ARRAY OF SKUS HERE");
$n=array();
foreach ($skus as $item) {
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $item)->getId();
array_push($n, $product);
}
View gist:c13a524c2b900da80143d81a52ee945f
git clone https://github.com/OpenMage/magento-mirror.git
cd public_html/shop
curl https://raw.githubusercontent.com/github/gitignore/master/Magento.gitignore > .gitignore
git init
git add --all
git commit -m 'backup'
git status
rsync
cd ..
ls
View cheat_csvkit.sh
#read xlsx
in2csv a.xlsx
#convert xlsx to csv (also works for xls)
in2csv a.xlsx > data.csv
#pretty print stdout spreadsheet
csvlook data.csv | less -S
#display column names
@mokanfar
mokanfar / magento-snippets.phtml
Last active Nov 27, 2018
Magento Snippets #2
View magento-snippets.phtml
magento product phtml data sku attribute get data
<?php echo $_product->getProductUrl() ?>
<?php echo $_product->getId() ?>
<?php echo $_product->getSku() ?>
###Customer ID Final Price Customer Group
<?php
require_once 'app/Mage.php';
Mage::app();
//to overwrite limit but you need first to increase your memory limit
$collection = Mage::getModel('catalog/product')->getCollection()
@mokanfar
mokanfar / jquery.js
Created Feb 21, 2018
$ jQuery snippets
View jquery.js
//===========
jQuery.noConflict();
(function ($) {
$(this).remove();
})(jQuery);
//===========
//===========
@mokanfar
mokanfar / ssync.sh
Last active Feb 7, 2018
Custom ERP -> Magento Stock Sync Shell Script. Handles kit parts in erp translates to a simple magento sku qty
View ssync.sh
#!/bin/bash
########## MAGENTO CONFIG VARIABLES #############
globalMagDir='/var/www/html/****'
globalScriptDir="${globalMagDir}/dev/stock-sync"
globalMagFeedDir="${globalMagDir}/media/amfeed/feeds"
amfeedF3='export_3'
amfeedF4='export_4'
########## MAGMI CONFIG VARIABLES ##############
magmiCLI="${globalMagDir}/magmi/magmi/cli/magmi.cli.php"
You can’t perform that action at this time.