ecmall 产品添加市场价

1.修改ecmall两个数据表,添加market_price字段

ALTER TABLE `ecm_goods` ADD `market_price` DECIMAL( 10,2 ) NOT NULL DEFAULT '0' AFTER `price` ;
ALTER TABLE `ecm_goods_spec` ADD `market_price` DECIMAL( 10,2 ) NOT NULL DEFAULT '0' AFTER `price` ;

2.需要修改/app/my_goods.app.php的几个地方

        switch ($goods['spec_qty'])
        {
            case 0: // 没有规格
                $specs[intval($_POST['spec_id'])] = array(
                    'market_price' => $this->_filter_price($_POST['market_price']),
                    'price' => $this->_filter_price($_POST['price']),
                    'stock' => intval($_POST['stock']),
                    'sku'      => trim($_POST['sku']),
                    'spec_id'  => trim($_POST['spec_id']),
                );
                break;
            case 1: // 一个规格
                $goods['spec_name_1'] = $spec_name_1 ? $spec_name_1 : $spec_name_2;
                $goods['spec_name_2'] = '';
                $spec_data = $spec_name_1 ? $_POST['spec_1'] : $_POST['spec_2'];
                foreach ($spec_data as $key => $spec_1)
                {
                    $spec_1 = trim($spec_1);
                    if ($spec_1)
                    {
                        if (($spec_id = intval($_POST['spec_id'][$key]))) // 已有规格ID的
                        {
                            $specs[$key] = array(
                                'spec_id' => $spec_id,
                                'spec_1' => $spec_1,
                                'market_price'  => $this->_filter_price($_POST['market_price'][$key]),
                                'price'  => $this->_filter_price($_POST['price'][$key]),
                                'stock'  => intval($_POST['stock'][$key]),
                                'sku'       => trim($_POST['sku'][$key]),
                            );
                        }
                        else  // 新增的规格
                        {
                            $specs[$key] = array(
                                'spec_1' => $spec_1,
                                'market_price'  => $this->_filter_price($_POST['market_price'][$key]),
                                'price'  => $this->_filter_price($_POST['price'][$key]),
                                'stock'  => intval($_POST['stock'][$key]),
                                'sku'       => trim($_POST['sku'][$key]),
                            );
                        }

                    }
                }
                break;
            case 2: // 二个规格
                $goods['spec_name_1'] = $spec_name_1;
                $goods['spec_name_2'] = $spec_name_2;
                foreach ($_POST['spec_1'] as $key => $spec_1)
                {
                    $spec_1 = trim($spec_1);
                    $spec_2 = trim($_POST['spec_2'][$key]);
                    if ($spec_1 && $spec_2)
                    {
                        if (($spec_id = intval($_POST['spec_id'][$key]))) // 已有规格ID的
                        {
                            $specs[$key] = array(
                                'spec_id'   => $spec_id,
                                'spec_1'    => $spec_1,
                                'spec_2'    => $spec_2,
                                'market_price'     => $this->_filter_price($_POST['market_price'][$key]),
                                'price'     => $this->_filter_price($_POST['price'][$key]),
                                'stock'     => intval($_POST['stock'][$key]),
                                'sku'       => trim($_POST['sku'][$key]),
                            );
                        }
                        else // 新增的规格
                        {
                            $specs[$key] = array(
                                'spec_1'    => $spec_1,
                                'spec_2'    => $spec_2,
                                'market_price'     => $this->_filter_price($_POST['market_price'][$key]),
                                'price'     => $this->_filter_price($_POST['price'][$key]),
                                'stock'     => intval($_POST['stock'][$key]),
                                'sku'       => trim($_POST['sku'][$key]),
                            );
                        }

                    }
                }
                break;
            default:
                break;
        }
 if (empty($default_spec))
            {
                $default_spec = array('default_spec' => $spec_id, 'market_price' => $spec['market_price'], 'price' => $spec['price']);
            }
 $default_spec = array(); // 更新商品中默认规格的信息
            foreach ($data as $key => $val)
            {
                if (empty($default_spec))
                {
                    $default_spec = array('price' => $val['price'], 'market_price' => $val['market_price']);
                }
                $this->_spec_mod->edit($key, $val);
            }
            $this->_goods_mod->edit($id, $default_spec);
 function save_spec($spec)
   {
        $data = array();
        if (empty($spec['price']) || empty($spec['stock']))
        {
            return $data;
        }
   		foreach ($spec['market_price'] as $key => $val)
        {
            $data[$key]['market_price'] = $this->_filter_price($val);
        }
        foreach ($spec['price'] as $key => $val)
        {
            $data[$key]['price'] = $this->_filter_price($val);
        }
        foreach ($spec['stock'] as $key => $val)
        {
            $data[$key]['stock'] = intval($val);
        }
        return $data;
   }

3.修改提交表单

themes/mall/default/my_goods.form.html

<li>
<h2  ectype="no_spec">市场价: </h2>
<div class="arrange"  ectype="no_spec"><input name="spec_id" value="{$goods._specs.0.spec_id}" type="hidden" /><input name="market_price" value="{$goods._specs.0.market_price}" type="text" class="text width_short" /></div>
</li>
<li>
<h2  ectype="no_spec">{$lang.price}: </h2>
<div class="arrange"  ectype="no_spec"><input name="spec_id" value="{$goods._specs.0.spec_id}" type="hidden" /><input name="price" value="{$goods._specs.0.price}" type="text" class="text width_short" /></div>
</li>

添加规格弹出窗口html修改

<ul class="th">
<li><input col="spec_name_1" type="text" class="text width4" /></li>
<li><input col="spec_name_2" type="text" class="text width4" /></li>
<li class="distance1">市场价</li>
<li class="distance1">{$lang.price}</li>
<li class="distance1">{$lang.stock}</li>
<li class="distance2">{$lang.sku}</li>
<li class="distance3">{$lang.handle}</li>
</ul>
<ul class="td" ectype="spec_item">
<li><input item="spec_1" type="text" class="text width4" /></li>
<li><input item="spec_2" type="text" class="text width4" /></li>
<li><input item="market_price" type="text" class="text width4" /></li>
<li><input item="price" type="text" class="text width4" /></li>
<li><input item="stock" type="text" class="text width4" /></li>
<li><input item="sku" type="text" class="text width8" /><input item="spec_id" type="hidden" /></li>
<li class="padding3">
<span ectype="up_spec_item" class="up_btn"></span>
<span ectype="down_spec_item" class="down_btn"></span>
<span ectype="drop_spec_item" class="delete_btn"></span>
</li>
</ul>

规格结果显示html修改

<table ectype="spec_result">
<tr>
<th col="spec_name_1">loading..</th>
<th col="spec_name_2">loading..</th>
<th col="price">市场价</th>
<th col="price">{$lang.price}</th>
<th col="stock">{$lang.stock}</th>
<th col="sku">{$lang.sku}</th>
</tr>
<tr ectype="spec_item" style="display:none">
<td item="spec_1"></td>
<td item="spec_2"></td>
<td item="market_price"></td>
<td item="price"></td>
<td item="stock"></td>
<td item="sku"></td>
</tr>
</table>

js需要修改的地方

/includes/libraries/javascript/goodsinfo.js

/* spec对象 */
function spec(id, spec1, spec2, price, market_price,stock)
{
    this.id    = id;
    this.spec1 = spec1;
    this.spec2 = spec2;
    this.price = price;
    this.market_price = market_price;
    this.stock = stock;
}

/includes/libraries/javascript/my_goods.js

var spec_1 = SPEC.spec_name_1 ? $.trim($(this).find('*[item="spec_1"]').val()) : null;
            var spec_2 = SPEC.spec_name_2 ? $.trim($(this).find('*[item="spec_2"]').val()) : null;
            var market_price = $.trim($(this).find('*[item="market_price"]').val());
            var price = $.trim($(this).find('*[item="price"]').val());
            var stock = $.trim($(this).find('*[item="stock"]').val());
        tpl.find('*[item="market_price"]').append('<input type="hidden" name="market_price['+ item.spec_id +']" value="' + item.market_price + '" />' + item.market_price);
        tpl.find('*[item="price"]').append('<input type="hidden" name="price['+ item.spec_id +']" value="' + item.price + '" />' + item.price);
        tpl.find('*[item="stock"]').append('<input type="hidden" name="stock['+ item.spec_id +']" value="' + item.stock + '" />' + item.stock);
        tpl.find('*[item="sku"]').append('<input type="hidden" name="sku['+ item.spec_id +']" value="' + item.sku + '" /><input type="hidden" name="spec_id['+ item.spec_id +']" value="' + item.spec_id + '" />' + item.sku);
        tpl.show();
        d_spec_item.before(tpl);
 spec_item && $.each(spec_item,function(i,item){ // 遍历生成规格项
        var tpl = d_spec_item.clone(true); // 克隆一个规格项
        tpl.attr('ectype', 'data'); // 赋值一个ectype与规格项模板区别
        item.spec_1 && tpl.find('*[item="spec_1"]').val(item.spec_1);
        item.spec_2 && tpl.find('*[item="spec_2"]').val(item.spec_2);
        tpl.find('*[item="market_price"]').val(item.market_price);
        tpl.find('*[item="price"]').val(item.price);
        tpl.find('*[item="stock"]').val(item.stock);
        tpl.find('*[item="sku"]').val(item.sku);
        tpl.find('*[item="spec_id"]').val(item.spec_id);
        tpl.show();
        d_spec_item.before(tpl); // 将克隆的规格项放到模板前面,新增的规格项能按正序排列
    });

修改下规格编辑窗口的宽度

/themes/mall/default/styles/default/css/user.css


.add_spec ul {
    overflow: hidden;
    width: 600px;
}

最终效果:
未添加规格时

开启规格时

Related Posts

    No related posts found

Related Search

This entry was posted in php and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>