示例#1
0
<?php

include "models/function.php";
IncludeClass::inc(array("Product"));
if (isset($_POST["go"])) {
    $nn = DB::selectAI("price");
    $attr = AttrValue::conbine($_POST["attr"], $_POST["val"]);
    if (isset($_POST["related"]) and $_POST["related"]) {
        $related = array_slice($_POST["related"], 0, 3);
        $data_related = serialize($related);
    } else {
        $data_related = "";
    }
    $arrText = array("section" => $_POST['section'], "collection" => $_POST['collection'], "exclusive" => $_POST['exclusive'], "name" => $_POST['name'], "nomer" => $_POST['nomer'], "code" => $_POST['code'], "size" => $_POST['size'], "material" => $_POST['material'], "proba" => $_POST['proba'], "vstavki" => $_POST['vstavki'], "weight" => $_POST['weight'], "price" => $_POST['price'], "price_old" => $_POST['price_old'], "attr" => $attr, "related" => $data_related, "title" => $_POST['title'], "description" => $_POST['description'], "keywords" => $_POST['keywords']);
    if ($_POST["go"] == "save") {
        $arrText += array('nn' => $nn, 'sk40' => 0, 'sk50' => 0);
        if (isset($arrText['related']) && !empty($arrText['related'])) {
            //$next_sql = " AND NOT id=";
            $proverka = DB::selectParam('price', 'nomer', $arrText['nomer'], false, false, false, false);
            $arr_prov = array("related" => $arrText['related']);
            if ($proverka != false && empty($proverka['related'])) {
                foreach ($proverka as $prov) {
                    DB::update(DB::updateSql("price", $arr_prov), $arr_prov, $prov['id']);
                }
            }
        }
        $lastId = DB::insert(DB::insertSql("price", $arrText), $arrText);
    } else {
        $lastId = $_POST["go"];
        if (isset($arrText['related']) && !empty($arrText['related'])) {
            $next_sql = " AND NOT id=" . $lastId;
示例#2
0
 /**
  * Save good attribute values from array
  * @param $data array with good attribute values
  */
 public function SaveFeatures($data)
 {
     //save good features
     if (!isset($data)) {
         return;
     }
     //check exist good features first
     $featureValues = GoodAttrVal::model()->findAllByAttributes(array('good_id' => $this->id));
     foreach ($featureValues as $featureValue) {
         if (isset($featureValue->attrValue)) {
             if ($featureValue->attrValue->attr->type == '1') {
                 //if feature is string type
                 if (empty($data['normal'][$featureValue->attrValue->attr->id])) {
                     $featureValue->delete();
                 } elseif ($data['normal'][$featureValue->attrValue->attr->id] != $featureValue->attr_value_id) {
                     if ($data['normal'][$featureValue->attrValue->attr->id] == '0') {
                         $featureValue->attr_value_id = $data['new'][$featureValue->attrValue->attr->id];
                     } else {
                         $featureValue->attr_value_id = $data['normal'][$featureValue->attrValue->attr->id];
                     }
                     $featureValue->save();
                 }
             }
         } elseif (isset($featureValue->attr)) {
             if ($featureValue->attr->type == '2') {
                 //if feature is boolean type
                 if ($data['normal'][$featureValue->attr->id] == '0') {
                     $featureValue->delete();
                 } elseif ($data['normal'][$featureValue->attr->id] != $featureValue->value) {
                     $featureValue->value = $data['normal'][$featureValue->attr->id];
                     $featureValue->save();
                 }
             } elseif ($featureValue->attr->type == '3') {
                 //if feature is numeric type
                 if (empty($data['normal'][$featureValue->attr->id])) {
                     $featureValue->delete();
                 } elseif ($data['normal'][$featureValue->attr->id] != $featureValue->value) {
                     $featureValue->value = $data['normal'][$featureValue->attr->id];
                     $featureValue->save();
                 }
             }
         }
     }
     $newFeature = TRUE;
     foreach ($data['normal'] as $featureId => $feature) {
         foreach ($featureValues as $featureValue) {
             if ($featureValue->attrValue !== null && $featureValue->attrValue->attr_id == $featureId) {
                 $newFeature = FALSE;
             }
             if ($featureValue->attr->id == $featureId) {
                 $newFeature = FALSE;
             }
         }
         if ($newFeature) {
             $attr = Attr::model()->findByPk($featureId);
             $newGoodFeature = new GoodAttrVal();
             $newGoodFeature->good_id = $this->id;
             if ($attr->type == '1') {
                 if ($feature == '0' && !empty($data['new'][$featureId])) {
                     //add new attribute value
                     $newAttrValue = new AttrValue();
                     $newAttrValue->attr_id = $attr->id;
                     $newAttrValue->value = $data['new'][$featureId];
                     $newAttrValue->save();
                     $newAttrValue->refresh();
                     $newGoodFeature->attr_value_id = $newAttrValue->id;
                     $newGoodFeature->save();
                 } elseif ($feature != '0') {
                     $newGoodFeature->attr_value_id = $feature;
                     $newGoodFeature->save();
                 }
             } elseif ($attr->type == '2' && $feature != '0') {
                 $newGoodFeature->value = $feature;
                 $newGoodFeature->attr_id = $featureId;
                 $newGoodFeature->save();
             } elseif ($attr->type == '3' && !empty($feature)) {
                 $newGoodFeature->value = $feature;
                 $newGoodFeature->attr_id = $featureId;
                 $newGoodFeature->save();
             }
         }
         $newFeature = TRUE;
     }
 }
示例#3
0
<?php

include "models/function.php";
if (isset($_POST["go"])) {
    $objImg = new UploadImg();
    $name_img = $objImg->upload($_FILES, $_POST["photo_now"]);
    $objAttr = new AttrValue();
    $data_attr = $objAttr->conbine($_POST["attr"], $_POST["val"]);
    if (isset($_POST["related"]) and $_POST["related"]) {
        $related = array_slice($_POST["related"], 0, 4);
        $data_related = serialize($related);
    } else {
        $data_related = "";
    }
    require_once "classes/Product.php";
    $obj = new Product();
    if ($_POST["go"] == "save") {
        $fff = $obj->insert($obj->insertSql(), trimStr($_POST["section"]), trimStr($_POST["name"]), trimStr($_POST["nomer"]), trimStr($_POST["brand"]), trimStr($_POST["viscous"]), trimStr($_POST["type"]), trimStr($_POST["volume"]), trimStr($_POST["kol"]), trimStr($_POST["price"]), trimStr($_POST["text"]), $data_related, $data_attr, trimStr($_POST["title"]), trimStr($_POST["description"]), trimStr($_POST["keywords"]), $name_img, trimStr($_POST["img_title"]), trimStr($_POST["img_alt"]));
        header("Location: production.php?id=" . $_POST["section"]);
    } else {
        $obj->update($obj->updateSql(), trimStr($_POST["section"]), trimStr($_POST["name"]), trimStr($_POST["nomer"]), trimStr($_POST["brand"]), trimStr($_POST["viscous"]), trimStr($_POST["type"]), trimStr($_POST["volume"]), trimStr($_POST["kol"]), trimStr($_POST["price"]), trimStr($_POST["text"]), $data_related, $data_attr, trimStr($_POST["title"]), trimStr($_POST["description"]), trimStr($_POST["keywords"]), $name_img, trimStr($_POST["img_title"]), trimStr($_POST["img_alt"]), $_POST['go']);
        header("Location: production.php?id=" . $_POST["section"]);
    }
}
if (isset($_GET["delete"])) {
    $delete = new Delete();
    $delete->del($_GET["title"], $_GET["delete"]);
    header("Location: production.php?id=" . $_GET["delete"]);
}
require_once "classes/Catalog.php";
$section = new Catalog();
示例#4
0
<label><?php 
echo Yii::t('main-ui', 'Good features');
?>
<br /></label>
<?php 
foreach ($model->category->attrGroups as $attr_group) {
    echo CHtml::openTag('div', array('class' => 'attr_group'));
    echo "<h3>" . $attr_group->name . "</h3>";
    foreach ($attr_group->attrs as $attr) {
        echo CHtml::label($attr->name, $attr->id);
        if ($attr->type == '1') {
            echo CHtml::dropDownList('Good[feature][normal][' . $attr->id . ']', $model->findAttrValue($attr), array('0' => ' ') + CHtml::listData(AttrValue::model()->findAllByAttributes(array('attr_id' => $attr->id)), 'id', 'value'));
            echo CHtml::textField('Good[feature][new][' . $attr->id . ']', '', array('class' => 'own-attr-value', 'size' => '50'));
        } else {
            if ($attr->type == '2') {
                echo CHtml::dropDownList('Good[feature][normal][' . $attr->id . ']', $model->findAttrValue($attr), array('0' => ' ', '1' => 'yes', '2' => 'no'));
            } else {
                if ($attr->type == '3') {
                    echo CHtml::textField('Good[feature][normal][' . $attr->id . ']', $model->findAttrValue($attr), array('size' => '10'));
                }
            }
        }
        echo '<br>';
    }
    echo CHtml::closeTag('div');
}
示例#5
0
 /**
  * Set good attribute value for string type attribute
  * @param $good
  * @param Attr $attr attribute
  * @param string $val value
  * @return bool
  */
 public function SetStringFeatureValue($good, $attr, $val)
 {
     foreach ($attr->attrValues as $exist_value) {
         if (strtolower($exist_value->value) == strtolower($val)) {
             $this->SetGoodAttribute($good, $attr->id, $exist_value->id);
             return;
         }
     }
     //if value not exist, create it
     $attrVal = new AttrValue();
     $attrVal->attr_id = $attr->id;
     $attrVal->value = $val;
     $attrVal->save();
     $this->SetGoodAttribute($good, $attr->id, $attrVal->id);
     return;
 }