$pm->filter_attr_arr = $filter_attr_arr; $pm->products_model = 'ali' . date('YmdHis'); $pm->products_afterbuy_model = $pm->products_model; //$url = 'http://www.aliexpress.com/fm-store/604445/211047357-530629675/Free-Shipping-Newest-Visible-Green-Smart-Charger-Sync-Cable-for-iPhone-iPod-Touch-iPad-indicate-how.html?promotionId=100009102'; //$url = 'aa.txt'; //$pm->html_content = file_get_contents('a.txt'); $pm->from_url = 'http://localhost/data/a.txt'; $pm->html_content = file_get_contents($pm->from_url); $msg = $pm->addProduct(); //$pm->getAttr(); $products_id = $pm->new_products_id; //$products_id = 159807;//echo $products_id;exit; echo '新增产品id:' . $products_id; echo '<br>'; if (1) { $product_attr = new ZencartProductAttrModel(); $attr_str_arr = $pm->attr_str_arr; $base_price = $pm->product_info['price']; foreach ($attr_str_arr as $key => $val) { //匹配属性标题 $preg_dt = "/<dt.*?>([\\s\\S]+?)</i"; preg_match($preg_dt, $val, $arr); $attr_name_tmp = ""; $attr_val_tmp_arr = array(); if (!empty($arr)) { $attr_name_tmp = str_replace(":", "", trim($arr[1])); } //forexample: size,color $opt_name_arr = array('attr_name' => $attr_name_tmp, 'attr_type' => 0); $product_attr->language = 3; //echo '<pre>';print_r($opt_name_arr);exit;
<?php $product_attr = new ZencartProductAttrModel(); //把属性名添加到数据库表 $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);