Skip to content

Instantly share code, notes, and snippets.

@AndresInSpace
AndresInSpace / insta-scrap-open-image.bookmarklet.js
Last active June 20, 2019 16:33
For Designers: Scrap IG Image using Bookmarklet JS+Alerts/Prompts
//add this as the URL of your bookmark, then just click the bookmark to trigger the script when you are on an IG page with an image selected.
javascript:(function(){var dialog = document.querySelector('.vCf6V'); var standAlone = document.querySelector('._97aPb'); if(!dialog && standAlone){ dialog = standAlone; } if(!dialog && !standAlone){ alert('Please open a IG image to scrape it.'); } else { dialog.querySelectorAll('.FFVAD').forEach(function(e){ var list = e.srcset.split(',').reverse(); list.forEach(function(source){ var sizeimg = source.split(' '); prompt('The image size is:'+sizeimg[1],sizeimg[0]) }) }) }})();
//alternative; opens largest image in new tab automatically
javascript:(function(){var dialog = document.querySelector('.vCf6V'); var standAlone = document.querySelector('._97aPb'); if(!dialog && standAlone){ dialog = standAlone; } if(!dialog && !standAlone){ alert('Please open a IG image to scrape it.'); } else { dialog.querySelectorAll('.FFVAD').forEach(function(e){ var list = e.srcset.split(','
@AndresInSpace
AndresInSpace / magento.bestsellers.catalog.category.collection.php
Created April 3, 2019 14:33
Magento 1 Bestsellers from Order Data (Not aggregated data)
/* Best Sellers Category */
$today = time();
$from = date('Y-m-d', strtotime("-12 months",$today));//pull best sellers from 12 months prior order data
$to = date("Y-m-d", $today);
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$orderTableAliasName = $readConnection->quoteIdentifier('order');
@AndresInSpace
AndresInSpace / qty-input-counter
Last active February 15, 2019 15:53
Qty Input Addition/Subtraction for IE10+ (w/ JQuery for delegation.. feel free to change to vanilla JS) https://codepen.io/AndresInSpace/pen/xMyeVO
var editQty = (function(){
function editValue(e) {
var input = e.target.nextElementSibling || e.target.previousElementSibling;
input.value = counter(e.target.classList.contains('plus'),input.value);
}
function counter(add,x) {
return add ? ++x : (x > 1 ? --x : x);
}
@AndresInSpace
AndresInSpace / My_Module.xml
Last active June 17, 2019 20:07
Magento Product Attribute Setup Installer - Add New Product Attribute & Add to All Attribute Sets to Specified Group - Full List of available params used for catalog_product addAttribute installation
filepath: app/etc/modules/
<?xml version="1.0"?>
<config>
<modules>
<My_Module>
<active>true</active>
<codePool>local</codePool>
</My_Module>
</modules>
</config>
@AndresInSpace
AndresInSpace / gist:3a7c4ca83abd043ec68b07cdbca0af75
Last active April 27, 2019 02:36
Magento 1 Add Product To Cart w Custom Options [CartController or Observer Methods]
$custom_option1 = array('label'=>'Custom1','value'=>$value1);
$custom_option2 = array('label'=>'Custom2','value'=>$value2);
$product->addCustomOption('additional_options', serialize(array($custom_option1,$custom_option2)));
$product->setHasOptions(true);
$cart->addProduct($product, $params);
$cart->save();
//USE 'additional_options' if you need the CustomOption to show up on checkout/cart, as $item->getCustomOptions() only looks at 'additional_options' and 'option_ids'
$item->getOptionByCode('option_ids');
default
catalog_category_default (* also used in directory.xml)
catalog_category_layered (* also used in directory.xml)
catalog_product_compare_index
catalog_product_gallery
catalog_product_send
catalog_product_view (* also used in customeralert.xml, tag.xml)
catalog_seo_searchterm_popular
catalog_seo_sitemap_category
catalog_seo_sitemap_product
@AndresInSpace
AndresInSpace / Varien.php
Created August 20, 2018 17:41
FIX Magento 1.9x Initial Session Creation (CORE BUG)
FILE PATH: app/code/core/Mage/Core/Model/Session/Abstract/Varien.php
// session cookie params
$cookieParams = array(
'lifetime' => $cookie->getLifetime(),
'path' => $cookie->getPath(),
- 'domain' => $cookie->getConfigDomain(),
+ 'domain' => $cookie->getDomain(),
'secure' => $cookie->isSecure(),
'httponly' => $cookie->getHttponly()
);
@AndresInSpace
AndresInSpace / jquery-bs-prototype-fix
Last active April 30, 2019 13:30
Fix Prototype JS Library conflicts with Bootstrap JS (with BS dependent on jQuery)
//ADD THIS TO END OF YOUR JQUERY FILE OR RUN IT AFTER JQUERY IS LOADED
// Prototype.js loads -> then jquery.js loads -> then run this
//alternatively, upgrade and load jquery 3 first then prototype.js and you shouldn't need this fix.
if(Prototype.BrowserFeatures.ElementExtensions){var disablePrototypeJS=function(o,e){var t=function(e){e.target[o]=void 0,setTimeout(function(){delete e.target[o]},0)};e.each(function(e){jQuery(window).on(o+".bs."+e,t)})},pluginsToDisable=["collapse","dropdown","modal","tooltip","popover"];disablePrototypeJS("show",pluginsToDisable),disablePrototypeJS("hide",pluginsToDisable)}
@AndresInSpace
AndresInSpace / magento-1.x-cheatsheet
Last active May 29, 2018 16:12
Magento 1.x Cheatsheet
//Get Layout Handles Used
var_dump(Mage::app()->getLayout()->getUpdate()->getHandles());
//Get loaded layout blocks
var_dump(array_keys(Mage::app()->getLayout()->getAllBlocks()));
//Add to Global Messages
Mage::getSingleton('core/session')->addSuccess('Success Message');
Mage::getSingleton('core/session')->addError('Error Message');
Mage::getSingleton('core/session')->addWarning('Warning Message');
@AndresInSpace
AndresInSpace / MagentoFastCategoryProductCollection
Last active October 4, 2018 18:51
Get Magento Product Collection filtered by category and ordered by product position from that category without loading category model and subsequent overhead
<?php
public function getProductCollection(){
if($_category = Mage::registry('current_category')){
$_categoryId = $_category->getId();
$_productCollection = Mage::getResourceModel('catalog/product_collection');
$_productCollection->joinTable(array('cp'=>'catalog/category_product'), 'product_id=entity_id', array('*') ,'cp.category_id='.$_categoryId, 'inner'); //join the table we need, filtered on Category ID
$_productCollection
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes()) //attributes needed from products using default config, or select your own
->addAttributeToFilter('status', 1) //ensure its enabled