Skip to content

Instantly share code, notes, and snippets.

@alexdrupal
alexdrupal / magento_eav_vs_flat.sql
Last active November 19, 2020 19:15
magento compare eav product vs flat table - check status attribute_id before run on your instance
SELECT e.sku, cp.sku FROM catalog_product_entity e LEFT JOIN catalog_product_entity_int ei ON e.entity_id = ei.entity_id AND ei.attribute_id = 87 LEFT JOIN catalog_product_flat_1 cp ON cp.sku = e.sku WHERE ei.value = 1 AND cp.sku is NULL
@alexdrupal
alexdrupal / magento_duplicate_labels.sql
Created November 5, 2019 12:30
Magento 1 SQL to get list of select options with duplicate labels
SELECT EAOV.value, count(EAOV.value) as cnt FROM eav_attribute EA LEFT JOIN eav_attribute_option EAO ON EAO.attribute_id = EA.attribute_id LEFT JOIN eav_attribute_option_value EAOV ON EAOV.option_id = EAO.option_id WHERE EA.attribute_code = 'ATTRIBUTE_CODE_HERE' AND EAOV.store_id = 0 GROUP BY EAOV.value HAVING cnt > 1;
@alexdrupal
alexdrupal / rsync_magento.sh
Created September 2, 2019 22:18
rsync magento1 instance
rsync -av --exclude=var/cache --exclude=media/captcha --exclude=media/catalog/product/cache --exclude=var/tmp --exclude=var/session --exclude=var/report SRC DEST
@alexdrupal
alexdrupal / objectbricks.js
Created January 5, 2019 13:48
Pimcore Object Bricks fixes
/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Enterprise License (PEL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
@alexdrupal
alexdrupal / mage_get_static_block.php
Created September 7, 2017 14:40
Magento. Get static block in template by identifier
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('delivery_returns')->toHtml() ?>
@alexdrupal
alexdrupal / mage_format_date.php
Created December 11, 2015 12:47
Magento format date in any format using store locale
<?php
$date = Mage::app()->getLocale()->date('01.01.2015');
echo $date->toString('F Y', 'php');
@alexdrupal
alexdrupal / mage_product_collection_filter_by_category.php
Last active August 29, 2015 13:57
Magento. Filter product collection by category including subcategories
<?php
if ($categoryIds) {
$subCategories = array();
$categoryIds = explode(',', $categoryIds);
foreach ($categoryIds as $categoryId) {
$category = Mage::getModel('catalog/category')->load($categoryId);
$subCategories += explode(',', $category->getChildren());
}
$collection->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id=entity_id', null, 'left')
->addAttributeToFilter('category_id', array('in' => array_merge($categoryIds, $subCategories)));
@alexdrupal
alexdrupal / mage_form_country.php
Created November 18, 2013 14:24
Magento add country select to Form
<?php
$fieldset->addField('country_id', 'select', array(
'name' => 'country_id',
'label' => $this->__('Country'),
'values' => Mage::getModel('adminhtml/system_config_source_country')->toOptionArray(),
))
@alexdrupal
alexdrupal / mage_collection_filter_date.php
Last active December 28, 2015 16:19
Filter Magento collection by date
<?php
$collection->addFieldToFilter('start_date',
array(
array('to' => Mage::getModel('core/date')->gmtDate('Y-m-d')),
array('start_date', 'null' => '')
)
);
$collection->addFieldToFilter('end_date',
array(
array('gteq' => Mage::getModel('core/date')->gmtDate('Y-m-d')),
@alexdrupal
alexdrupal / views3_birthdays
Last active December 23, 2015 08:19
Views Contextual filter values to display a list of users with today's birthday
$results = db_query("SELECT entity_id FROM field_data_field_birthday WHERE DATE_FORMAT(field_birthday_value,'%m-%d') = DATE_FORMAT(NOW(),'%m-%d') AND entity_type = 'user'");
$ids = array();
foreach ($results as $result) {
$ids[] = $result->entity_id;
}
return implode(',',$ids);