Če želimo pohitriti izvajanje osvežitev produktov potem je boljše, da izvedemo to s sql stavki. Z njimi lahko osvežimo le atribute katere mi želimo, v tem blogu bom zapisal kako zapisati pravilen update za short in long description.
Kako dobimo attribute_id iz mysql?
attribute_id je definiran v tabeli eav_attribute. Tako za short description in description dobimo:
- attribute_id=36 entity_type_id=3 in attribute_code=description
- attribute_id=61 entity_type_id=4 in attribute_code=description
- attribute_id=62 entity_type_id=4 in attribute_code=short_description
Sedaj še moramo pogledati, kaj pomeni entity_type_id (tabela eav_entity_type):
- entity_type_id=3 entity_type_code=catalog_category
- entity_type_id=4 entity_type_code=catalog_product
Mi bomo osvežili produkte, zato izberemo description in short_description, kjer je entity_type_id=4.
Update produktov
Produkte pa osvežimo z naslednjim sql stavkom:
-
UPDATE catalog_product_entity_text val
-
INNER JOIN catalog_product_entity AS product ON product.entity_id=val.entity_id
-
SET val.value = '$shortDesc' WHERE val.store_id=0 AND val.attribute_id = 62 AND product.sku='$sku'
Za description je enak query, le attribute_id=61 in ne 62.
Na koncu moramo še pobrisati cache ter reindexirati:
-
$allTypes = Mage::app()->useCache();
-
foreach($allTypes as $type => $blah) {
-
if ($type == 'block_html' || $type == 'collections' || $type == 'eav') {
-
Mage::app()->getCacheInstance()->cleanType($type);
-
}
-
}
-
Mage::getSingleton('index/indexer')->getProcessByCode('catalog_product_attribute')->reindexAll();
Več o indexih (kazalih) v Magentu: http://spletnisistemi.si/blog/2012/03/01/kazala-v-magentu-magento-indexes/
Podobni članki:
- Magento massive products import with database query
- Magento slow product save and update
- Add SQL queries with new Magento extension version
- Razlika med tipi produktov v spletni trgovini Magento
- Magento – število izdelkov na zalogi
- Magento – mass update magento attribute back to Use Default Value
- Magento – razvoj novih modulov – debugiranje
- Magento – add attribute to attribute programmaticaly with sql
- Magento – working with queries
- Magento – remove payment method depend on delivery time