Skip to content

Instantly share code, notes, and snippets.

View IvanChepurnyi's full-sized avatar
🚀
Building awesome high performance microservices

Ivan Chepurnyi IvanChepurnyi

🚀
Building awesome high performance microservices
View GitHub Profile
@IvanChepurnyi
IvanChepurnyi / OrderController.php
Created July 19, 2012 13:11
Any reason for using collection to retrieve single address instead of using load method of model?
// From app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php
/**
* Edit order address form
*/
public function addressAction()
{
$addressId = $this->getRequest()->getParam('address_id');
$address = Mage::getModel('sales/order_address')
->getCollection()
->addFilter('entity_id', $addressId)
@IvanChepurnyi
IvanChepurnyi / gist:4136339
Last active July 30, 2020 12:01
Abstract Rule Conditions Based on Properties, not attributes
/**
* Abstract rule condition based on properties
*/
abstract class EcomDev_Rule_Model_Rule_Condition_Abstract extends Mage_Rule_Model_Condition_Abstract
{
protected $_properties = null;
/**
* Should return a label of the current condition
*
@IvanChepurnyi
IvanChepurnyi / Table.php
Last active July 11, 2022 10:44
Optimized options load
<?php
/**
* Optimized version of attribute source options model
*
* That allows to preload options once and reuse them instead of doing calls to db all the time
*
*/
class EcomDev_Optimization_Model_Resource_Attribute_Source_Table
extends Mage_Eav_Model_Entity_Attribute_Source_Table
@IvanChepurnyi
IvanChepurnyi / Observer.php
Created September 16, 2013 22:31
Optimized catalog price rules
<?php
class EcomDev_Optimization_Model_Rule_Observer extends Mage_CatalogRule_Model_Observer
{
protected $_preloadedPrices = array();
public function beforeCollectTotals(Varien_Event_Observer $observer)
{
$quote = $observer->getQuote();
$date = Mage::app()->getLocale()->storeTimeStamp($quote->getStoreId());
@IvanChepurnyi
IvanChepurnyi / vhost.conf
Created September 27, 2013 23:47
This simple rewrite will help you to run phpunit from PHPStorm in Vagrant box without patching php.jar
location ~ ^/_intellij_phpunit_launcher.php$ {
expires off; ## Do not cache dynamic content
set $args "$args&dir=$document_root&config=phpunit.xml.dist";
fastcgi_pass unix://var/run/php5-fpm.sock; # Replace with your fpm pass
fastcgi_read_timeout 600;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}
@IvanChepurnyi
IvanChepurnyi / config.xml
Created November 5, 2013 09:37
Disable Mage_Log module observers
<config>
<frontend>
<controller_action_predispatch>
<observers>
<log>
<type>disabled</type>
</log>
</observers>
</controller_action_predispatch>
<controller_action_postdispatch>
@IvanChepurnyi
IvanChepurnyi / config.xml
Created November 5, 2013 09:41
Disable Mage_Reports module
<config>
<frontend>
<catalog_product_compare_remove_product>
<observers>
<reports>
<type>disabled</type>
</reports>
</observers>
</catalog_product_compare_remove_product>
<customer_login>
@IvanChepurnyi
IvanChepurnyi / Layout.php
Last active August 29, 2015 14:19
<remove /> strange behaviour, with core acl="" attribute for layout file.
<?php
// This code allows all calls to <remove /> being ignored
// if a block with acl attribute is valid for admin user.
// Shall I keep it in LayoutCompiler? IMO, this looks more like a bug, than a needed feature!
foreach ($ignoreNodes as $block) {
if ($block->getAttribute('ignore') !== null) {
continue;
}
$acl = (string)$attributes->acl;
if ($acl && Mage::getSingleton('admin/session')->isAllowed($acl)) {
@IvanChepurnyi
IvanChepurnyi / Proposal.md
Last active June 26, 2020 22:22
Architectural Proposal for Magento 2 Inventory and Prices Mechanism

Problem

There are too tight relations of stock and prices to store views and websites in Magento that results in high complexity of implementation of b2b and drop shipping solutions in Magento.

The issue was very visible with the price index structure for Magento 1, and now Magento 2 stock index follows the same idea of having an index entry per website.

This strict relation to a website makes unnecessary data duplications in case if you have global stock. Although it makes over complicated multi-warehouse delivery, as you will be required to create a separate website for each warehouse, that duplicates other product data in the flat index structure and price index.

Solution

Create a separate scope entity for Price and Inventory, for using them as scope fields for respective data structures.

Verifying that +ivanchepurnyi is my blockchain ID. https://onename.com/ivanchepurnyi