Magento IMP 3


Getting A Products URL

Potentially confusing due to the 3 methods you could use, all of which are inMage_Catalog_Model_Product:
public function getUrlPath($category=null) public function getUrlInStore($params = array()) public function getProductUrl($useSid = null)
The best way to explain is to simply show the results of several calls. Given a product whose URL key is mondrian-large-coffee-table-set-multicolour on the domain of http://made.local the results are:
$product->getUrlPath(); 'mondrian-large-coffee-table-set-multicolour' $product->getUrlPath($category); 'tables/mondrian-large-coffee-table-set-multicolour' // you cannot stop this method adding ___store to the URL, even by setting _store_to_url to false $product->getUrlInStore(); 'http://made.local/tables/mondrian-large-coffee-table-set-multicolour?___store=default' // you cannot stop this method adding ___store to the URL, even by setting _store_to_url to false // note - see the "using _ignore_category" section below for an arguable bug with using this param $product->getUrlInStore(array('_ignore_category' => true)); 'http://made.local/mondrian-large-coffee-table-set-multicolour?___store=default' $product->getProductUrl(); 'http://made.local/tables/mondrian-large-coffee-table-set-multicolour' $product->getProductUrl(true); 'http://made.local/tables/mondrian-large-coffee-table-set-multicolour'
To see what other params can be passed togetUrlInStore(), see URL Route Parameters.

Using _ignore_category

The short version - I would not use this param, and instead useMage::getUrl($product->getUrlPath())
If you first fetch a products URL which includes the category, and then use the same product instance to attempt to fetch a non-category URL, you will instead both times get a URL which contains the category, see the below code:
$product = Mage::getModel('catalog/product'); $product->getUrlInStore(); 'http://made.local/sofas/jonah-2-seater-sofa-berry-red?___store=default' $product->getUrlInStore(array('_ignore_category' => true)); 'http://made.local/sofas/jonah-2-seater-sofa-berry-red?___store=default' $product = Mage::getModel('catalog/product'); $product->getUrlInStore(array('_ignore_category' => true)); 'http://made.local/jonah-2-seater-sofa-berry-red?___store=default'
The issue lies with therequest_path key on the$product model, which theMage_Catalog_Model_Product_Url::getUrl()sets, to act as a cached value for an otherwise intensive process of resolving a URL rewrite to a product within a category.
To resolve this, unsetrequest_path first, as below:
$product->unsRequestPath(); $product->getUrlInStore(array('_ignore_category' => true)); 'http://made.local/jonah-2-seater-sofa-berry-red?___store=default'
Note that any method listed at the top of this card which causes the category to be present in the returned URL will have the same effect of caching the category.

Product Price Index

The Display Out Of Stock Configuration Option is implemented by this index. If you have chosen not to display out of stock products, then the effect is that a product is not entered into this index.
These tables seem to supply the data for the price index:
TableNotes
catalogindex_pricehas data
catalog_product_index_pricehas data - main table
catalog_product_index_price_bundle_idxno data
catalog_product_index_price_bundle_opt_idxno data
catalog_product_index_price_bundle_opt_tmpno data
catalog_product_index_price_bundle_sel_idxno data
catalog_product_index_price_bundle_sel_tmpno data
catalog_product_index_price_bundle_tmpno data
catalog_product_index_price_cfg_opt_agr_idxno data
catalog_product_index_price_cfg_opt_agr_tmpno data
catalog_product_index_price_cfg_opt_idxno data
catalog_product_index_price_cfg_opt_tmpno data
catalog_product_index_price_downlod_idxno data
catalog_product_index_price_downlod_tmpno data
catalog_product_index_price_final_idxno data
catalog_product_index_price_final_tmpno data
catalog_product_index_price_idxhas data
catalog_product_index_price_opt_agr_idxno data
catalog_product_index_price_opt_agr_tmpno data
catalog_product_index_price_opt_idxno data
catalog_product_index_price_opt_tmpno data
catalog_product_index_price_tmphas data
From looking at query logs,catalog_product_index_priceis the main table, as it is the only one that is included in any queries when loading a category or product page. I assume that all the rest of the tables are temporary.

Display Out Of Stock Configuration Option

The decision of whether to show or hide a product based on this setting is implemented by the Product Price Index. You can verify this by changing the setting to "Yes" and then viewing a category with an out of stock product; you see the product is present. If you then change the setting to "No" and view the category again you will see the out of stock product is still present. You will also notice that these two indexes now need refreshing:
  • Product Attributes (catalog_product_attribute)
  • Product Prices (catalog_product_price)
If you then refresh just the "Product Attributes" index, the product is still visible, if you then refresh the "Product Prices" index, it disappears, thus the "Product Prices" index is responsible for the implementation of this setting.

Setting Data Per-Store On Entites

Certain entities have the concept of a store scope, whereby you can set the default value for all stores, or you can set a value on a per-store basis. To do this in code you must set the store id before you load the model, as such:
To set the name of a category for the default store scope:
$category = Mage::getModel('catalog/category'); $category->setStoreId(0); $category->load(100); $category->setName('Default Category Name'); $category->save();
To set the name on store 1:
$category = Mage::getModel('catalog/category'); $category->setStoreId(1); $category->load(100); $category->setName('Store 1 Category Name'); $category->save();
The concept of callingsetStoreId() is also used for other models that use a store scope, such as products.


Altering Config Data During Setup

Assuming $installer refers toMage_Core_Model_Resource_Setupor a subclass of it, you can do the following:
Setting a value in the default scope:
$installer->setConfigData('some/path', 'value');
Setting a value in a specific store:
$installer->setConfigData('some/path', 'value', 'stores', 1);
Deleting a value from all scopes:
$installer->deleteConfigData('some/path');
Deleting a value from a certain scope (unfortunately you cannot choose which scope ID though:
$installer->deleteConfigData('some/path', 'stores');

Cache Clearing And General Information

Clean everything (use either):
Mage::app()->getCacheInstance()->flush(); Mage::app()->getCache()->clean();
Clean specific types:
Mage::app()->getCacheInstance()->cleanType('config'); Mage::app()->getCacheInstance()->cleanType('layout'); Mage::app()->getCacheInstance()->cleanType('block_html'); Mage::app()->getCacheInstance()->cleanType('translate'); Mage::app()->getCacheInstance()->cleanType('collections'); Mage::app()->getCacheInstance()->cleanType('eav'); Mage::app()->getCacheInstance()->cleanType('config_api'); Enterprise_PageCache_Model_Cache::getCacheInstance()->cleanType('full_page');
Get all declared cache types:
Mage::app()->getCacheInstance()->getTypes();

Cache Types

Each cache has it’s own type id, which is a Magento concept to aid management of each type of cache, basically you would use the type id to clear by that type. Each type corresponds to a tag or a set of tags which will be cleaned when you clean that type. To find out the info for all the currently declared types use the "Get all declared cache types" snippet above andvar_dump() it.
All cache types are stored in config, in the pathglobal/cache/types, so you could also use something like the Magento Debug Toolbar to inspect the config stored at that path.

Configuration

Type ID: config
Tags: CONFIG

Layouts

Type ID: layout
Tags:LAYOUT_GENERAL_CACHE_TAG

Blocks HTML output

Type ID: block_html
Tags: BLOCK_HTML

Translations

Type ID: translate
Tags: TRANSLATE

Collections Data

Type ID: collections
Tags: COLLECTION_DATA

EAV types and attributes

Type ID: eav
Tags: EAV

Web Services Configuration

Type ID: config_api
Tags: CONFIG_API

(Full) Page Cache

Type ID: full_page
Tags: FPC
Note - full page cache is normally kept in a seperate cache backend, so you should use it’s own cache manager to reliably clear it

Set Next Increment ID For Orders, Quotes, Invoices, Shipments or Credit Memos

BIG NOTE! I’m not totally sure that all these entity types increment ID’s are stored here any more. Check
The last order increment ID issued for all these entity types is stored ineav_entity_store, in theincrement_last_id column. Note that this is the last ID, so if you wish your next ID to be 100065000, then you must set yourincrement_last_id to be 100064999. Also bear in mind that increment IDs are per store, so you need to decide which store you are updating the increment ID for, and find out the store ID.

Orders

UPDATE eav_entity_store INNER JOIN eav_entity_type ON eav_entity_type.entity_type_id = eav_entity_store.entity_type_id SET eav_entity_store.increment_last_id = '100064999' WHERE eav_entity_type.entity_type_code = 'order' AND eav_entity_store.store_id = 1;

Quotes

UPDATE eav_entity_store INNER JOIN eav_entity_type ON eav_entity_type.entity_type_id = eav_entity_store.entity_type_id SET eav_entity_store.increment_last_id = '100064999' WHERE eav_entity_type.entity_type_code = 'quote' AND eav_entity_store.store_id = 1;

Invoices

UPDATE eav_entity_store INNER JOIN eav_entity_type ON eav_entity_type.entity_type_id = eav_entity_store.entity_type_id SET eav_entity_store.increment_last_id = '100064999' WHERE eav_entity_type.entity_type_code = 'invoice' AND eav_entity_store.store_id = 1;

Shipments

UPDATE eav_entity_store INNER JOIN eav_entity_type ON eav_entity_type.entity_type_id = eav_entity_store.entity_type_id SET eav_entity_store.increment_last_id = '100064999' WHERE eav_entity_type.entity_type_code = 'shipment' AND eav_entity_store.store_id = 1;

Credit Memos

UPDATE eav_entity_store INNER JOIN eav_entity_type ON eav_entity_type.entity_type_id = eav_entity_store.entity_type_id SET eav_entity_store.increment_last_id = '100064999' WHERE eav_entity_type.entity_type_code = 'creditmemo' AND eav_entity_store.store_id = 1;

General Info

The table looks like the following:
entity_store_identity_type_idstore_idincrement_prefixincrement_last_id
1100000017379
21111100058797
31611100056714
42311100004946
51122200000503
61622200000493
72322200000113
entity_type_id
The type of the entity for which the increment relates. This is a foreign key which relates to eav_entity_type, and through it’s foreign table relates to one of quote, order, invoice, shipment or creditmemo
store_id
Fairly obvious
increment_prefix
The first digit of theincrement_last_id
increment_last_id
Fairly obvious

Get The Current Category

Mage::registry('current_category');

Get The Current Product

Mage::registry('current_product');

No comments:

Post a Comment