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
(copied from current development PHP file)
 
imported>Woozle
(updated name of source query in STAGE 2; added about/history)
Line 1: Line 1:
==About==
* '''History''':
** '''2009-12-10''' Transcribed from development source; updated name of source query in STAGE 2
==PHP code==
==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.
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.
Line 18: Line 21:
/* STAGE 2: Calculate stock numbers and set isForSale flag */
/* STAGE 2: Calculate stock numbers and set isForSale flag */
   /* -- calculate stock quantities; set for-sale flag if in stock */
   /* -- calculate stock quantities; set for-sale flag if in stock */
   'calculate stock quantities and status' => 'UPDATE ctg_upd2 AS i LEFT JOIN v_stk_items_remaining AS s ON i.ID_Item=s.ID_Item
   '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
   SET
     i.qtyInStock=s.QtyForSale,
     i.qtyInStock=s.QtyForSale,

Revision as of 22:27, 10 December 2009

About

  • History:
    • 2009-12-10 Transcribed from development source; updated name of source query in STAGE 2

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. */

 'clear update table 1 of 2'	=> 'DELETE FROM ctg_upd1;',
 'clear update table 2 of 2'	=> 'DELETE FROM ctg_upd2;',
 /* == Fill temp tables == */
   /* -- generated source data: */
 '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: */
 '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 */
 '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 */
 '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) */
 'update item status with calculated items'	=> 'REPLACE INTO cat_items
 SELECT *
 FROM qryCtg_Upd_join;',
  /* -- clear availability flags in any unused items */
 '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 */
 '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 */
 '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 */

 'update cache timestamp'			=> 'UPDATE data_tables SET WhenUpdated=NOW() WHERE Name="cat_items";'
 );</php>