Skip to content

Instantly share code, notes, and snippets.

View fballiano's full-sized avatar

Fabrizio Balliano fballiano

View GitHub Profile
@fballiano
fballiano / file.patch
Last active August 29, 2015 14:02
Duplicate primary on catalog_product_index_price_tmp
+++ b/app/code/core/Mage/Index/Model/Resource/Abstract.php
@@ -176,6 +176,7 @@ abstract class Mage_Index_Model_Resource_Abstract extends Mage_Core_Model_Resour
if ($from === $to) {
$query = $select->insertFromSelect($destTable, $columns);
+ $query = str_replace("INSERT INTO", "INSERT IGNORE INTO", $query);
@fballiano
fballiano / sitemap.patch
Created June 26, 2014 12:21
Magento EE 1.13 does not use suffix in sitemap.xml generation => all urls go 404
diff --git a/app/code/core/Mage/Sitemap/Model/Resource/Catalog/Category.php b/app/code/core/Mage/Sitemap/Model/Resource/Catalog/Category.php
index 5c82f40..63ecf21 100644
--- a/app/code/core/Mage/Sitemap/Model/Resource/Catalog/Category.php
+++ b/app/code/core/Mage/Sitemap/Model/Resource/Catalog/Category.php
@@ -102,7 +102,22 @@ class Mage_Sitemap_Model_Resource_Catalog_Category extends Mage_Sitemap_Model_Re
*/
protected function _getEntityUrl($row, $entity)
{
- return !empty($row['request_path']) ? $row['request_path'] : 'catalog/category/view/id/' . $entity->getId();
+ $suffix = Mage::helper('catalog/category')->getCategoryUrlSuffix();
@fballiano
fballiano / controller.php
Created July 17, 2014 09:20
Magento: controller bootstrapping layout and messages
public function indexAction()
{
$this->loadLayout();
$this->_initLayoutMessages("customer/session");
$this->_initLayoutMessages("catalog/session");
$this->renderLayout();
}
@fballiano
fballiano / apply_promotion_rules.php
Created July 21, 2014 14:33
Apply promotion rules, for Magento EE 1.13, CE 1.8
<?php
require_once 'app/Mage.php';
ini_set('display_errors', 1);
Mage::setIsDeveloperMode(true);
umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
try {
Mage::getModel('catalogrule/rule')->applyAll();
Mage::getModel('catalogrule/flag')->loadSelf()
<?php
require_once 'abstract.php';
class Shell_Delete_Old_Enterprise_Staging_Backups extends Mage_Shell_Abstract
{
public function run()
{
$actions = Mage::getModel("enterprise_staging/staging_action")->getCollection()
->addFieldToFilter("type", "backup")
93c93,106
< $taxClassAmount = array_merge($taxClassAmount, $shippingTax);
---
> $_weees = Mage::helper('tax')->getAllWeee($this->getOrder());
> $wees = array();
> foreach ($_weees as $name => $value) {
> $wees[] = array(
> "tax_amount" => $value,
> "base_tax_amount" => $value,
> "title" => $name,
@fballiano
fballiano / magento2-province-italiane.sql
Last active October 8, 2015 09:26
Magento2 Province Italiane (da archivio ufficiale ISTAT, aggiornamento 02/08/2015).
INSERT INTO directory_country_region (country_id, default_name, code) VALUES ('IT','Agrigento','AG');
INSERT INTO directory_country_region (country_id, default_name, code) VALUES ('IT','Alessandria','AL');
INSERT INTO directory_country_region (country_id, default_name, code) VALUES ('IT','Ancona','AN');
INSERT INTO directory_country_region (country_id, default_name, code) VALUES ('IT','Arezzo','AR');
INSERT INTO directory_country_region (country_id, default_name, code) VALUES ('IT','Ascoli Piceno','AP');
INSERT INTO directory_country_region (country_id, default_name, code) VALUES ('IT','Asti','AT');
INSERT INTO directory_country_region (country_id, default_name, code) VALUES ('IT','Avellino','AV');
INSERT INTO directory_country_region (country_id, default_name, code) VALUES ('IT','Bari','BA');
INSERT INTO directory_country_region (country_id, default_name, code) VALUES ('IT','Barletta-Andria-Trani','BT');
INSERT INTO directory_country_region (country_id, default_name, code) VALUES ('IT','Belluno','BL');
<?php
define('MAGENTO', realpath(dirname(__FILE__)));
require_once MAGENTO . '/app/Mage.php';
Mage::app();
umask(0);
Mage::app('default');
Mage::getSingleton('core/session', array('name' => 'adminhtml'));
$user = Mage::getModel('admin/user')->loadByUsername('admin'); // Here admin is the Username
if (Mage::getSingleton('adminhtml/url')->useSecretKey()) Mage::getSingleton('adminhtml/url')->renewSecretUrls();
@fballiano
fballiano / customer_session.php
Created July 17, 2014 09:06
Magento: start customer session from custom script
<?php
require_once "app/Mage.php";
umask(0);
Mage::app();
Mage::singleton("core/session", array("name"=>"frontend"));
$session = Mage::getSingleton("customer/session");
if ($session->isLoggedIn()) {
} else {
@fballiano
fballiano / load_collection.php
Last active January 21, 2018 11:17
Magento product collections, general loading
<?php
$store_id = Mage::app()->getStore()->getId();
$collection = Mage::getModel("catalog/product")->getCollection();
$collection->setStoreId($store_id);
$collection->addStoreFilter($store_id);
//$collection->addAttributeToSelect("*");
$collection->addAttributeToFilter('status', array('in' => array(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)));
$collection->addAttributeToFilter('visibility', array('in '=> array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG, Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)));
Mage::getSingleton("cataloginventory/stock")->addInStockFilterToCollection($collection);