ecshop 屬性表(attribute)商品屬性表(goods_attr)貨品表(prduct) 商品數量的聯系


ecshop 屬性表(attribute)商品屬性表(goods_attr)貨品表(prduct) 商品數量的聯系

一個商城的商品屬性存放在屬性表(attribute)里 ,每個商品對應的屬性在goods_attr里 goods_attr與(attribute)想關聯,商品表里有商品數量的字段goods_number
為什么有這個貨品表呢?
 因為 某件商品有多種屬性的時候,那這個商品就成為了貨品,也就是說不同屬性的相同商品應該也存在差異,所以當設置商品屬性的attr_type=1(表示單選屬性)的時候,
在 前台include/lib_comment.php 函數sort_goods_attr_id_array將 goods_attr_id 的序列按照 attr_id 重新排序 可以找到 非規格屬性的id會被排除這句話,在連接這個函數寫的sql語句
/重新排序
    $sql = "SELECT a.attr_type, v.attr_value, v.goods_attr_id
            FROM " .$GLOBALS['ecs']->table('attribute'). " AS a
            LEFT JOIN " .$GLOBALS['ecs']->table('goods_attr'). " AS v
                ON v.attr_id = a.attr_id
                AND a.attr_type = 1
            WHERE v.goods_attr_id " . db_create_in($goods_attr_id_array) . "
            ORDER BY a.attr_id $sort";
我個人覺得attr_type=1表示規格屬性,然后就是由於這樣的處理,導致attr_type=0 attr_type=2的商品 他們雖然有商品數量,但是貨品庫存查不出來從而導致到貨通知這個功能出現異常
首先我們來看看這個到貨通知是怎樣處理的:
    從模板goods.dwt里我們找到
        function changePrice()
{
  var attr = getSelectedAttributes(document.forms['ECS_FORMBUY']);
  var qty = document.forms['ECS_FORMBUY'].elements['number'].value;
if(qty <=0 ){
 document.forms['ECS_FORMBUY'].elements['number'].value = 1;
 qty = 1;
}
  Ajax.call('goods.php', 'act=price&id=' + goodsId + '&attr=' + attr + '&number=' + qty, changePriceResponse, 'GET', 'JSON');
}

/**
 * 接收返回的信息
 */
function changePriceResponse(res)
{
  if (res.err_msg.length > 0)
  {
    alert(res.err_msg);
  }
  else
  {
        document.forms['ECS_FORMBUY'].elements['number'].value = res.qty;

        if (document.getElementById('ECS_GOODS_AMOUNT')){
          document.getElementById('ECS_GOODS_AMOUNT').innerHTML = res.result;
        }
       if(document.getElementById('ECS_GOODS_NUMBER')){
        document.getElementById('ECS_GOODS_NUMBER').innerHTML = res.goods_attr_number;
            if(res.goods_attr_number > 0){
                document.getElementById('ECS_ADD_TO_CART').style.display="block";
                document.getElementById('ECS_ONE_STEP_BUY').style.display="block";
                document.getElementById('ECS_DAOHUO').style.display="none";
            }else{
                document.getElementById('ECS_ADD_TO_CART').style.display="none";
                document.getElementById('ECS_ONE_STEP_BUY').style.display="none";
                document.getElementById('ECS_DAOHUO').style.display="block";
            }
就是這里,通過發送一個ajax請求回傳到goods.php里,得到最終的attr,然后在goods.php里通過:
//-- 改變屬性、數量時重新計算商品價格
/*------------------------------------------------------ */

if (!empty($_REQUEST['act']) && $_REQUEST['act'] == 'price')
{
    include('includes/cls_json.php');

    $json   = new JSON;
    $res    = array('err_msg' => '', 'result' => '', 'qty' => 1);

    $attr_id    = isset($_REQUEST['attr'])&&!empty($_REQUEST['attr']) ? explode(',', $_REQUEST['attr']) : array();
    $number     = (isset($_REQUEST['number'])) ? intval($_REQUEST['number']) : 1;

    if ($goods_id == 0)
    {
        $res['err_msg'] = $_LANG['err_change_attr'];
        $res['err_no']  = 1;
    }
    else
    {
        if ($number == 0)
        {
            $res['qty'] = $number = 1;
        }
        else
        {
            $res['qty'] = $number;
        }
        $exclusive = $GLOBALS['db']->getOne("select exclusive from ".$GLOBALS['ecs']->table('goods')." where goods_id = $goods_id");
        $shop_price  = get_final_price($goods_id, $number, true, $attr_id);
        $res['is_exclusive']  = is_exclusive($exclusive,$shop_price);
        $res['result'] = price_format($shop_price * $number);
        $res['result_jf'] = floor($shop_price * $number);
        $res['goods_attr_number'] = get_product_attr_num($goods_id,$_REQUEST['attr']);
回傳json數據到模板,通過if(document.getElementById('ECS_GOODS_NUMBER')){
        document.getElementById('ECS_GOODS_NUMBER').innerHTML = res.goods_attr_number;
            if(res.goods_attr_number > 0){
                document.getElementById('ECS_ADD_TO_CART').style.display="block";
                document.getElementById('ECS_ONE_STEP_BUY').style.display="block";
                document.getElementById('ECS_DAOHUO').style.display="none";
            }else{
                document.getElementById('ECS_ADD_TO_CART').style.display="none";
                document.getElementById('ECS_ONE_STEP_BUY').style.display="none";
                document.getElementById('ECS_DAOHUO').style.display="block";
            }就可以實現到貨通知
我們在來看看這個 goods_attr_number在php頁面是怎樣得到的
$res['goods_attr_number'] = get_product_attr_num($goods_id,$_REQUEST['attr']);----attr是ajax調來的數據,往上找會看到它的處理
繼續找get_product_attr_num
get_product_attr_num 獲取相關屬性的庫存* @param int $goodid 商品id * @param string(array) $attrids 商品屬性id的數組或者逗號分開的字符串
仔細看函數的流程,我們發現如果一個商品沒有屬性,那它的attrid就是空的,又一個商品有多個屬性,那就對應多個goods_attr_id
在這里的話  goods_attr_number =就直接等於商品表里goods_number對應的數量
好了,再往下看,如果有屬性,那么就  重新排序 就是我上面提到的方法
問題就在這里了,那我們在看看后台商品屬性功能
在編輯屬性處有這樣三個單選,屬性是否可選:唯一屬性  單選屬性  復選屬性    而這里就是attr_type對應 的三種值
在頁面有這樣的說明:
選擇"單選/復選屬性"時,可以對商品該屬性設置多個值,同時還能對不同屬性值指定不同的價格加價,用戶購買商品時需要選定具體的屬性值。選擇"唯一屬性"時,商品的該屬性值只能設置一個值,用戶只能查看該值。
但是 出現問題來了,如果沒有選擇單單選屬性 那么在商品列表里或者再添加商品的時候這個商品的屬性不是單選屬性那么就不會出現貨品管理這個功能
因為在這個功能處也有個邏輯
在后台的goods.php里找到:
/* 獲取商品規格列表 */
    $attribute = get_goods_specifications_list($goods_id);
在lib_goods.php里找到里這個函數
/**
 * 獲取商品類型中包含規格的類型列表
 *
 * @access  public
 * @return  array
 */
function get_goods_type_specifications()
{
    // 查詢
    $sql = "SELECT DISTINCT cat_id
            FROM " .$GLOBALS['ecs']->table('attribute'). "
            WHERE attr_type = 1";
    $row = $GLOBALS['db']->GetAll($sql);

    $return_arr = array();
    if (!empty($row))
    {
        foreach ($row as $value)
        {
            $return_arr[$value['cat_id']] = $value['cat_id'];
        }
    }
    return $return_arr;
}
不難發現,這里也只有attr_type = 1 才會出現貨品這個功能
我就不明白了 為什么復選屬性也不行  唯一屬性能理解嘛  它還是等同於一個商品  真的沒弄明白ecshop在這里的設計,請朋友知道的私信我:2064320087@qq.com  非誠勿擾


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM