Skip to content

Instantly share code, notes, and snippets.

View evgv's full-sized avatar
🏠
Working from home

Eugene Zubkov evgv

🏠
Working from home
View GitHub Profile
@evgv
evgv / mage_get_customer_account_urls.md
Created July 12, 2016 15:34
Magento. Get customer account urls.
/*Check if customer loggen id */
Mage::helper('customer')->isLoggedIn();

/* Get log in url */
Mage::helper('customer')->getLoginUrl();

/* Get register url */
Mage::helper('customer')->getRegisterUrl()
@evgv
evgv / mage_serach_result_stock_filter.md
Created July 15, 2016 10:38
Magento. Search result stock filter.

Override _getSearchableProducts function in class Mage_CatalogSearch_Model_Resource_Fulltext so that it always searches in-stock products.

File to modify: app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php

/**
 * Retrieve searchable products per store
 *
 * @param int $storeId
@evgv
evgv / mage_cart_get_items_count.md
Created August 8, 2016 11:53
Magento. Get cart get items count.
/* return shopping cart items count means how many sku add to shopping cart. */
Mage::helper('checkout/cart')->getItemsCount() 

/* return shopping cart items summary (suppose you add sku1 6 qty and sku2 3 qty = total 9 qty return) */
Mage::helper('checkout/cart')->getSummaryCount()
@evgv
evgv / mage_disable_compilation.md
Last active June 14, 2017 23:20
Magento. Disable compilation.

Via Admin Panel

Navigate to System > Tools > Compilation page and click on Disable button
Navigate to System > Cache Management screen and use Flush Cache button.

Via SFTP

To disable compilation in Magento, edit includes/config.php. At around line 28, uncomment the first line and comment out the second:

@evgv
evgv / mage_retrieve_full_product_url.md
Created August 9, 2016 07:37
Magento. Retrieve full product url.
   /**
    * Retrieve full path of url including category
    * 
    * @param Mage_Catalog_Model_Product $product
    * @return string url
    */
    public function getFullProductUrl($product)
    {
@evgv
evgv / php_unique_merge_array.md
Created August 16, 2016 13:05
PHP. Unique merge of two array with sort.
array_unique(array_merge($array1,$array2), SORT_REGULAR);
@evgv
evgv / css_adaptive_youtube_video.md
Created August 17, 2016 15:02
CSS. Adaptive YouTube video

Create a container div around the iframe code and give it a class

<div class="video-container"><iframe></iframe></div>

Add in the CSS

@evgv
evgv / social_create_simple_share_links.md
Last active October 6, 2016 13:27
Social. Create simple share links.
@evgv
evgv / mage_add_new_product_attribute_and_add_to_all_sets.md
Last active August 24, 2016 07:38
Magento. Add new product attribute and add it to all attribute sets.
/* @var $installer Mage_Catalog_Model_Resource_Setup */
$installer = Mage::getResourceModel('catalog/setup','default_setup');

$attributeCode = "oversized";
$installer->startSetup();

$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode, array(
    'group'                         => 'General',
@evgv
evgv / mage_sql_copy_description_to_short_description.md
Last active August 29, 2016 09:42
Magento. SQL. Copy product description attribute to short description.
UPDATE catalog_product_entity_text AS A

SET A.value = (
			SELECT B.value
			FROM (SELECT * FROM catalog_product_entity_text) AS B
			WHERE B.attribute_id = 72
			AND B.entity_id = A.entity_id
 AND B.store_id = A.store_id