Storage.php 1.08 KB
<?php

/**
 * 商品库存
 * User: ziy
 * Date: 14-7-22
 * Time: 下午6:32
 */
class YHMCart_Hook_Cart_Storage extends YHMCart_Hook_Abstract
{
    static function run(YHMCart_Hook_Orders $package)
    {
        $package = $package->getTmpGoods();
        $storage = YHMProduct_Models_Stock_Client::getStockBySku($package['product_sku']);
        $productInfo = YHMProduct_Models_Goods_Client::getOneByProductSkc($package['product_skc']);
        if (empty($storage) || $storage['stock_number'] < $package['buy_number']) {
            $productName = '你选择的商品';
             if (!empty($productInfo)) {
              $productName = $productInfo['goods_name'];   
             }
            $txt=$productName . '已售罄';
            throw new Exception($txt, 400);
        }
            if (!empty($productInfo)) {
                $productName = $productInfo['goods_name'];
                if ($productInfo['status']==0)
                {
                  $txt= '商品已无效,请联系卖家';
                  throw new Exception($txt, 400);  
                } 
            }
    }
}