Skip to content

Instantly share code, notes, and snippets.

<?php
//grab the category
$category = Mage::registry('current_category');
//if category exists see if it is a parent category
if ($category)
{
$category = $category;
@Modicrumb
Modicrumb / gist:5767152
Created June 12, 2013 16:59
Magento Product Exporter
<?php
//THIS SCRIPT JUST INITIALS THE PROFILE TO BE RUN VIA MAGENTO ADMIN "RUN PROFILE IN POPUP". Its the same thing as click just via this file that you can run via cron
$profileId = 1; // SYSTEM - IMPORT/EXPORT - ADVANCED PROFILES <-- you need to go into your magento admin and grab the exact profile ID
ini_set('memory_limit', '-1');
require_once 'app/Mage.php';
umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
@Modicrumb
Modicrumb / gist:5775471
Created June 13, 2013 17:10
Manufacturers dynamically Created
<ul id="manufacturers">
<?php
$attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'manufacturer');
foreach ($attribute->getSource()->getAllOptions() as $option)
{
if ($option['label'])
{
//$cleanlink = str_replace(array(" ","'","_","."),array("-","","-",""),strtolower($option['label']));
$urlKey = str_replace("'", '', $option['label']);
@Modicrumb
Modicrumb / gist:5777132
Last active December 18, 2015 11:39
Magento delete all products 1.7.0.2
TRUNCATE TABLE `catalog_product_bundle_option`;
TRUNCATE TABLE `catalog_product_bundle_option_value`;
TRUNCATE TABLE `catalog_product_bundle_selection`;
TRUNCATE TABLE `catalog_product_entity_datetime`;
TRUNCATE TABLE `catalog_product_entity_decimal`;
TRUNCATE TABLE `catalog_product_entity_gallery`;
TRUNCATE TABLE `catalog_product_entity_int`;
TRUNCATE TABLE `catalog_product_entity_media_gallery`;
TRUNCATE TABLE `catalog_product_entity_media_gallery_value`;
TRUNCATE TABLE `catalog_product_entity_text`;
//---------------------- GET THE PRODUCTS
$products = Mage::getModel ( 'catalog/product' )->getCollection ();
$products->addAttributeToFilter ( 'status', 1 ); //enabled
$products->addAttributeToFilter ( 'visibility', 4 ); //catalog, search
$products->addFieldToFilter(array(
array('attribute'=>'cost','gt'=>0)));
$products->addFieldToFilter(array(
array('attribute'=>'type_id','eq'=>'simple')));
@Modicrumb
Modicrumb / gist:5877588
Created June 27, 2013 15:46
rest of it
foreach ( $prodIds as $productId ) {
//echo '. ';
//flush();
//echo 'Loop start: '.memory_get_usage(false).'<br>';
//flush();
$product = Mage::getModel('catalog/product')->load ( $productId );
//check stock info so we dont add a product thats out of stock
//also check if upc is valid
/* Import Function */
function is_upca($upc)
{
if (strlen((string)$upc)==12)
{
//commence extra steps
if (preg_match('/[a-z]/i',$upc))
{
return false;
}
@Modicrumb
Modicrumb / gist:5901806
Created July 1, 2013 15:24
Tier 1 Import Help for Daniel
$description .= $model . ". The " . $make . " " . $model . " catalytic converter meets both EPA requirements, as well as OEM vehicle manufacture standards. This catalytic converter is built to last, ensuring that your " . $year . " " . $make . " " . $model . " emissions are within EPA regulations.";
$TierI[$_Row]['description'] = $description;
$TierI[$_Row]['meta_keywords'] = $year . " " . $make . " " . $model . " Catalytic Converter";
$TierI[$_Row]['meta_description'] = "This " . $year . " " . $make . " " . $model . " Catalytic Converter is designed to last while meeting both EPA requirements, as well as OEM vehicle manufacture standards.";
@Modicrumb
Modicrumb / gist:5922636
Created July 3, 2013 20:43
Truncate Tables before backup Magento
//mysql for truncating all tables
TRUNCATE `log_customer`;
TRUNCATE `log_quote`;
TRUNCATE `log_summary`;
TRUNCATE `log_summary_type`;
TRUNCATE `log_url`;
TRUNCATE `log_url_info`;
TRUNCATE `log_visitor`;
@Modicrumb
Modicrumb / gist:6073795
Created July 24, 2013 19:39
My first drupal module
<?php
/* This module creates a custom block which users are not allowed to be able to alter*/
/**
* Implements hook_help.
*
* Displays help and module information.
*
* @param path