Skip to content

Instantly share code, notes, and snippets.

@mokanfar
mokanfar / filter_unique_rows_script.sh
Last active October 23, 2018 23:01
Matched Rows, Unique Rows Merge Filter Bash Scripts for CSV files
#!/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
<?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 August 24, 2018 17:58
get all images associated with an array of product sku's programatically in Magento [first one is base/main image]
@mokanfar
mokanfar / bulk_set_array_of_skus_attribute_programatically_in_magento.php
Last active July 18, 2018 00:45
Magento update from list of skus an attribute programatically
<?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);
}
@mokanfar
mokanfar / gist:c13a524c2b900da80143d81a52ee945f
Created June 15, 2018 23:44
Magento correct upgrade path
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
@mokanfar
mokanfar / cheat_csvkit.sh
Created March 23, 2018 08:00
csvkit commands
#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 November 27, 2018 19:52
Magento Snippets #2
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 February 21, 2018 18:09
$ jQuery snippets
//===========
jQuery.noConflict();
(function ($) {
$(this).remove();
})(jQuery);
//===========
//===========
@mokanfar
mokanfar / ssync.sh
Last active February 7, 2018 03:51
Custom ERP -> Magento Stock Sync Shell Script. Handles kit parts in erp translates to a simple magento sku qty
#!/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"
@mokanfar
mokanfar / rsync_magento-mirror
Last active June 28, 2017 23:58
rsync magento-mirror repo to upgrade magento
cd ~
git clone https://github.com/OpenMage/magento-mirror.git
cd public_html
git init
curl https://raw.githubusercontent.com/github/gitignore/master/Magento.gitignore > .gitignore
git add --all
git commit -m 'backup'
cd ../magento-mirror
rsync -chavzP --exclude='./var/cache' --exclude='./.git' --exclude='./media/catalog/product/cache' --exclude='./var/tmp' --exclude='./var/session' --exclude='./var/report' --stats ./ ../public_html