示例#1
0
 protected function getProductType()
 {
     //获取全部标签
     $mc_product_type = md5('mc_product_type_key');
     $proTypes = Yii::app()->cache->get($mc_product_type);
     if (!$proTypes) {
         $proTypes = array();
         $productType_model = new ProductType();
         $condition_attr = array('order' => " type_sort ");
         $res = $productType_model->findAll($condition_attr);
         foreach ($res as $val) {
             $proTypes[$val['id']] = $val->getAttributes();
         }
         Yii::app()->cache->set($mc_product_type, $proTypes, 600);
     }
     uasort($proTypes, array($this, '_sortHandlers'));
     return $proTypes;
 }
 public function product_update($id = null)
 {
     if (is_null($id)) {
         redirect(get_url('plugin/ecommerce'));
     }
     if (!($product = Product::findById($id))) {
         Flash::set('error', __('Product not found!'));
         redirect(get_url('plugin/ecommerce'));
     }
     if (get_request_method() == 'POST') {
         //get new type id if a new one was created
         if ($_POST['product_type']['title']) {
             //save type
             $type_id = $this->_product_save(null, 'product_type', 'ProductType');
             $_POST['product']['type_id'] = $type_id;
             //add new type page
             $page_data = array("is_protected" => 1, "parent_id" => 87, "title" => $_POST['product_type']['title'], "slug" => $_POST['product_type']['slug'], "breadcrumb" => $_POST['product_type']['title']);
             $page = new Page($page_data);
             $page->save();
         }
         //get new vendor id if a new one was created
         if ($_POST['product_vendor']['title']) {
             //save vendor
             $vendor_id = $this->_product_save(null, 'product_vendor', 'ProductVendor');
             $_POST['product']['vendor_id'] = $vendor_id;
             //add new vendor page
             $page_data = array("is_protected" => 1, "parent_id" => 86, "title" => $_POST['product_vendor']['title'], "slug" => $_POST['product_vendor']['slug'], "breadcrumb" => $_POST['product_vendor']['title']);
             $page = new Page($page_data);
             $page->save();
         }
         //save product
         $product_id = $this->_product_save($id, 'product', 'Product');
         //insert log
         $this->_insert_log('Product <a href="' . get_url('plugin/ecommerce/product_update/' . $product_id) . '">' . $_POST['product']['title'] . '</a> was updated.');
         //save images
         if (isset($_SESSION['product_images'])) {
             $this->_images_save($product_id, $_SESSION['product_images']);
         }
         //save product page
         $product = Product::findById($id);
         if ($product) {
             $page = Record::findByIdFrom('Page', $product->page_id);
             $page_data = array("is_protected" => 1, "title" => $_POST['product']['title'], "slug" => $_POST['product']['slug'], "breadcrumb" => $_POST['product']['title'], "created_on_time" => null, "published_on_time" => null);
             $page->setFromData($page_data);
             $page->save();
         }
         redirect(get_url('plugin/ecommerce/product'));
     }
     $types = ProductType::findAll();
     $vendors = ProductVendor::findAll();
     $images = Record::findAllFrom('ProductImage', 'product_id=? order by position', array($id));
     $variants = Record::findAllFrom('ProductVariant', 'product_id=? order by position', array($id));
     $files = Record::findAllFrom('ProductFile', 'product_id=? order by position', array($id));
     $videos = Record::findAllFrom('ProductVideo', 'product_id=? order by position', array($id));
     $this->display('ecommerce/views/products/update', array('action' => 'update', 'product' => $product, 'types' => $types, 'vendors' => $vendors, 'images' => $images, 'variants' => $variants, 'files' => $files, 'videos' => $videos));
 }