VbzCart/docs/pieces/catalog/building/2009: Difference between revisions

From Woozle Writes Code
< VbzCart‎ | docs‎ | pieces‎ | catalog‎ | building
Jump to navigation Jump to search
imported>Woozle
(line numbering; line formatting)
imported>Woozle
(doc: requirements)
Line 1: Line 1:
==About==
==About==
* '''Requires''': {{vbzcart/query|qryCtg_src}}, {{vbzcart/query|qryCtg_Items_forUpdJoin}}, {{vbzcart/query|qryStk_items_remaining}}, {{vbzcart/query|qryCtg_Upd_join}}, {{vbzcart/query|qryCat_Titles}}
* '''History''':
* '''History''':
** '''2009-12-10''' Transcribed from development source; updated name of source query in STAGE 2; added statement numbers for debugging purposes and changed line formatting for better readability
** '''2009-12-10''' Transcribed from development source; updated name of source query in STAGE 2; added statement numbers for debugging purposes and changed line formatting for better readability

Revision as of 17:25, 11 December 2009

About

PHP code

This defines the array which stores the SQL commands to be executed, in order. The key to each array element is the description to be shown to the administrator when executing that command. <php>$arSQL_CtgBuild = array( /* STAGE 1: Clear/refill the two temporary tables from which cat_items is updated. */

 '1.1 clear update table 1 of 2'	=> 'DELETE FROM ctg_upd1;',
 '1.2 clear update table 2 of 2'	=> 'DELETE FROM ctg_upd2;',
 /* == Fill temp tables == */
   /* -- generated source data: */
 '1.3 fill update table 1/2 with source data'
  => 'INSERT INTO ctg_upd1 SELECT

CatSfx, isCloseOut, ID_CTG_Title, ID_CTG_Item, ID_Title, ID_ItTyp, ID_ItOpt, ID_ShipCost, PriceBuy, PriceSell, PriceList, ItOpt_Descr_part, NameSng, GrpItmDescr, TitleGroupDescr, OptionDescr, ItOpt_Sort, GrpCode, GrpDescr, GrpSort, IDS_Item, CatNum, ItOpt_Descr

     FROM qryCtg_src;',
   /* -- existing catalog data indexed for JOINing: */
 '1.4 fill update table 2/2 with pre-join data'
   => 'INSERT INTO ctg_upd2 SELECT *, 0 AS cntDups
     FROM qryCtg_Items_forUpdJoin
     ON DUPLICATE KEY UPDATE cntDups=cntDups+1;',

/* STAGE 2: Calculate stock numbers and set isForSale flag */

  /* -- calculate stock quantities; set for-sale flag if in stock */
 '2.1 calculate stock quantities and status'
   => 'UPDATE ctg_upd2 AS i LEFT JOIN qryStk_items_remaining AS s ON i.ID_Item=s.ID_Item
     SET

i.qtyInStock=s.QtyForSale, i.isForSale=(s.QtyForSale > 0);',

  /* -- also set for-sale flag if available from source */
 '2.2 also update status from catalog source'
   => 'UPDATE ctg_upd2 AS i LEFT JOIN ctg_upd1 AS u ON i.IDS_Item=u.IDS_Item
     SET i.isForSale=i.isForSale OR (u.IDS_Item IS NOT NULL);',

/* STAGE 3: Update cat_items */

  /* -- replace sourced items in cat_items from CTG data (except for fields saved in ctg_upd2) */
 '3.1 update item status with calculated items'
   => 'REPLACE INTO cat_items
     SELECT *
     FROM qryCtg_Upd_join;',
  /* -- clear availability flags in any unused items */
 '3.2 clear availability flags in unused items'
   => 'UPDATE cat_items AS i
     LEFT JOIN qryCtg_Upd_join AS u

ON i.ID=u.ID SET i.isInPrint=NULL, i.isForSale=NULL WHERE u.ID IS NULL;', /* NOT FINISHED -- isn't there one more flag? */

  /* -- set stock and for-sale fields for *all* joinable cat_items from calculations done in ctg_upd2 */
 '3.3 set stock status fields'
   => 'UPDATE cat_items AS i LEFT JOIN ctg_upd2 AS u ON i.ID=u.ID_Item
     SET

i.isForSale=u.isForSale;',

  /* -- update inactive catalog numbers where title's catnum has changed */
 '3.4 update changed inactive catalog numbers'
   => 'UPDATE cat_items AS i LEFT JOIN qryCat_Titles AS t ON i.ID_Title=t.ID
     SET

i.CatNum=CONCAT_WS("-",t.CatNum,i.CatSfx)

     WHERE (LEFT(i.CatNum,LENGTH(t.CatNum)) != t.CatNum) AND NOT isPulled;',

/* STAGE 4: Housekeeping - update timestamp of cat_items so dependent tables will be recalculated */

 '4. update cache timestamp'
   => 'UPDATE data_tables
     SET WhenUpdated=NOW() WHERE Name="cat_items";'

);</php>