Update magento produktov s sql stavki

Č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:

SQL:
  1. UPDATE catalog_product_entity_text val
  2. INNER JOIN catalog_product_entity AS product ON product.entity_id=val.entity_id
  3. 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:

PHP:
  1. $allTypes = Mage::app()->useCache();
  2. foreach($allTypes as $type => $blah) {
  3.     if ($type == 'block_html' || $type == 'collections' || $type == 'eav') {
  4.         Mage::app()->getCacheInstance()->cleanType($type);
  5.         }
  6.     }
  7. 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:

  1. Magento massive products import with database query
  2. Magento slow product save and update
  3. Add SQL queries with new Magento extension version
  4. Razlika med tipi produktov v spletni trgovini Magento
  5. Magento – število izdelkov na zalogi
  6. Magento – mass update magento attribute back to Use Default Value
  7. Magento – razvoj novih modulov – debugiranje
  8. Magento – add attribute to attribute programmaticaly with sql
  9. Magento – working with queries
  10. Magento – remove payment method depend on delivery time

Dodaj komentar