SELECT t1.sa_shoppingcartid,
       t1.sa_brandid,
       t1.itemid,
       t3.itemname,
       t1.itemno,
       t1.sa_promotionid,
       t1.sa_promotion_itemsid,
       t1.tradefield tradefield_shoppingcart,
       t2.brandname,
       t1.qty,
       t1.length,
       t1.width,
       t1.cheek,
       t1.colors,
       t1.material,
       t3.model,
       t3.spec,
       t3.orderminqty,
       t3.orderaddqty,
       t3.orderminqty_auxunit,
       t3.orderaddqty_auxunit,
       t3.iscustomsize,
       t3.pricingmetod,
       t3.widthschemeid,
       t3.lengthschemeid,
       t4.unitname,
       t5.unitgroupname,
       t6.unitname auxunitname,
       t3.materialschemeid,
       t3.colorschemeid,
       t3.cheekschemeid,
       if(t1.sa_promotionid>0,ifnull(t7.packageqty,0),ifnull(t3.packageqty,0)) packageqty,
       t3.sa_customschemeid,
       t3.custamount
FROM sa_shoppingcart t1
         LEFT JOIN sa_brand t2 ON t2.sa_brandid = t1.sa_brandid AND t2.siteid = t1.siteid
         LEFT JOIN plm_item t3 ON t3.itemid = t1.itemid AND t3.siteid = t1.siteid
         LEFT JOIN plm_unit t4 ON t4.unitid = t3.unitid AND t4.siteid = t1.siteid
         LEFT JOIN plm_unitgroup t5 ON t5.unitgroupid = t3.unitgroupid AND t5.siteid = t1.siteid
         LEFT JOIN plm_unit t6 ON t6.unitid = t5.auxunitid AND t5.siteid = t1.siteid
         LEFT JOIN sa_promotion_items t7 ON t7.sa_promotion_itemsid = t1.sa_promotion_itemsid AND t7.siteid = t1.siteid
WHERE t1.sys_enterpriseid = $sys_enterpriseid$
  AND t1.siteid = $siteid$ and t3.istool = $istool$ and t1.sa_promotionid=$sa_promotionid$
  and $where$