<?php 
$attr_model = new ProductAttrModel();
$all_attrs = $attr_model->getAllAttributes();
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<div id="attr_container" style="display:none;margin-top:20px;">
<fieldset>
	<legend>为一个产品添加属性<input type="button" name="button" onclick="addNewAttr()" value="添加新属性" /></legend>
    <input type="hidden" name="curr_attr_number" id="curr_attr_number" value="1" />
	<div class="attr_box">

		<p>
				<b>输入新的属性名</b>:<input type="text" style="width:300px;" name="attr_name[1]" value="" />&nbsp;&nbsp;&nbsp;&nbsp;
				
				<b>或者选择已经存在的属性名</b>:
				<select onchange="getAttributeValues(this)" name="attr_name_selects[1]">
					<option value="0">请选择属性...</option>
					<?php 
foreach ($all_attrs as $key => $val) {
    ?>
					<option value="<?php 
    echo $val['products_options_id'];
    ?>
"><?php 
    echo $val['products_options_name'];
    ?>
</option>
					<?php 
}
?>
<?php

$product_attr = new ProductAttrModel();
//把属性名添加到数据库表
$attr_name = $_POST['attr_name'] ? trim($_POST['attr_name']) : '';
$attr_type = $_POST['attr_type'] ? trim($_POST['attr_type']) : '0';
$arr = array('attr_name' => $attr_name, 'attr_type' => $attr_type);
if (empty($language_id)) {
    $language_id = $_POST['language_id'] ? trim($_POST['language_id']) : '3';
}
$product_attr->language = $language_id;
$msg .= $product_attr->addProductsOptions($arr);
//把属性值添加到数据库表
$attr_values = $_POST['attr_value'] ? $_POST['attr_value'] : array();
$attr_sort = $_POST['attr_sort'] ? $_POST['attr_sort'] : array();
$arr = array('option_val' => $attr_values, 'attr_sort' => $attr_sort);
$msg .= $product_attr->addProductsOptionsValues($arr);
//把产品和属性关联起来
if (empty($products_id)) {
    $products_id = $_POST['products_id'] ? trim($_POST['products_id']) : '';
}
if (empty($products_id)) {
    die('产品id为空,不能添加产品属性');
}
$attr_price = $_POST['attr_price'] ? $_POST['attr_price'] : array();
$attr_weight = $_POST['attr_weight'] ? $_POST['attr_weight'] : array();
$arr = array('products_id' => $products_id, 'attr_price' => $attr_price, 'attr_weight' => $attr_weight, 'attr_sort' => $attr_sort);
$msg .= $product_attr->addProductsAttributes($arr);
예제 #3
0
<?php

include 'includes/init.php';
include 'includes/add_product_base.php';
include 'includes/product_attr_model.php';
$act = $_REQUEST['act'] ? $_REQUEST['act'] : '';
$all_categories = zen_get_categories();
//getAttrValues
if ($act == 'getAttrValues') {
    $attr_id = $_REQUEST['attr_id'] ? $_REQUEST['attr_id'] : '0';
    $attr_model = new ProductAttrModel();
    $attr_values = $attr_model->getAttributeValues($attr_id);
    $result = array('status' => 'success', 'content' => $attr_values);
    die(json_encode($result));
}
if ($act == 'save_detail') {
    $is_added_by_hand = true;
    include 'add_product_init.php';
    $is_set_attr = $_POST['is_set_attr'] ? $_POST['is_set_attr'] : 0;
    /**/
    //产品主图----begin
    //产品图片前面不能有images/
    $products_image = trim($_REQUEST['products_image']);
    $products_image = preg_replace('/\\?.*/i', '', $products_image);
    //如果输入的产品图片是外站的url
    if (preg_match("#^http(s?)://#", $products_image)) {
        $new_products_image = date('Ymd') . '/' . date('YmdHis') . strrchr($products_image, '.');
        if (!is_dir(dirname(IMAGE_PATH . $new_products_image))) {
            @mkdir(dirname(IMAGE_PATH . $new_products_image), 0777, true);
        }
        if (!is_file(IMAGE_PATH . $new_products_image)) {