예제 #1
0
 public function actionCreate()
 {
     $model = new Product();
     $description = new ProductDescription();
     $image = new XUploadForm();
     $userImages = array();
     $thumbs = array();
     if (!isset($_POST[$this->modelName])) {
         Yii::app()->user->setState('product_images', NULL);
         Yii::app()->user->setState('thumbs', NULL);
     }
     //$product_option_value = new ProductOptionValue;
     $this->performAjaxValidation(array($model, $description), 'product-form');
     if (isset($_POST[$this->modelName])) {
         $model->setAttributes($_POST[$this->modelName]);
         $description->setAttributes($_POST[$this->modelName . 'Description']);
         $suc = Yii::t('info', 'Product was successfully created');
         $err = Yii::t('info', 'Could not create Product');
         $description->product_id = 0;
         $description->locale_code = Yii::app()->getLanguage();
         //$description->link = str_replace(' ','-',trim(strtolower(str_replace('_','-',preg_replace('/(?<![A-Z])[A-Z]/', '\0', $description->name)))));
         $description->link = strtolower(str_replace(' ', '-', preg_replace('!\\s+!', ' ', trim(preg_replace("/[^A-Za-z ]/", ' ', $description->name)))));
         $userImages = Yii::app()->user->getState('product_images');
         $thumbs = Yii::app()->user->getState('thumbs');
         if (Yii::app()->user->hasState('thumbs')) {
             if ($this->validateProduct($model, $description)) {
                 if ($model->save()) {
                     $description->product_id = $model->id;
                     $description->save();
                     $this->addImages($model->id, 'Image', 'thumbs', 'Product');
                     $tpath = realpath(UtilityHelper::yiiparam('frontPath') . '/www' . $model->thumbs[0]->source);
                     $timage = Yii::app()->image->load($tpath);
                     $timage->resize(200, 200);
                     $timage->save();
                     $this->productSave($model);
                     Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, $suc);
                     if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                         $this->renderPartial('_view', array('model' => $model, 'description' => $description, 'option' => $this->_productoption, 'attribute' => $this->_productattribute), false, true);
                         Yii::app()->end();
                     } else {
                         $this->redirect(array('view', 'id' => $model->id));
                     }
                 } else {
                     Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, $err);
                 }
             }
         } else {
             Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, Yii::t('info', 'Please upload an image'));
         }
     }
     if (Yii::app()->getRequest()->getIsAjaxRequest()) {
         $this->renderPartial('_form_product', array('model' => $model, 'description' => $description, 'option' => $this->_productoption, 'attribute' => $this->_productattribute, 'thumbs' => $thumbs, 'image' => $image, 'userImages' => $userImages, 'discount' => $this->_productdiscount, 'special' => $this->_productspecial), false, true);
         Yii::app()->end();
     }
     $this->render('create', array('model' => $model, 'description' => $description, 'option' => $this->_productoption, 'attribute' => $this->_productattribute, 'thumbs' => $thumbs, 'image' => $image, 'userImages' => $userImages, 'discount' => $this->_productdiscount, 'special' => $this->_productspecial));
 }
예제 #2
0
 public function actionAutocomplete($query)
 {
     $json = array();
     $descriptions = ProductDescription::model()->findAll("name LIKE '%{$query}%' ");
     foreach ($descriptions as $description) {
         $json[] = array('id' => $description->product_id, 'value' => $description->name);
     }
     echo CJSON::encode($json);
 }
 /**
  * WFormRelationHasMany::delete
  */
 public function testDeleteWithoutCascade()
 {
     $product = $this->_getProductWithRelation(1, array('cascadeDelete' => false));
     $this->assertNotEmpty($product->description);
     $id = $product->description->primaryKey;
     $this->assertTrue($product->delete());
     $this->assertNotEmpty(ProductDescription::model()->findByPk($id));
 }
예제 #4
0
 public function afterDelete()
 {
     // delete dependencies
     ProductAttribute::model()->deleteAll("product_id={$this->cacheId}");
     ProductDescription::model()->deleteAll("product_id={$this->cacheId}");
     ProductDiscount::model()->deleteAll("product_id={$this->cacheId}");
     ProductFilter::model()->deleteAll("product_id={$this->cacheId}");
     ProductImage::model()->deleteAll("product_id={$this->cacheId}");
     ProductOption::model()->deleteAll("product_id={$this->cacheId}");
     ProductOptionValue::model()->deleteAll("product_id={$this->cacheId}");
     ProductRelated::model()->deleteAll("product_id={$this->cacheId}");
     ProductRelated::model()->deleteAll("related_id={$this->cacheId}");
     ProductReward::model()->deleteAll("product_id={$this->cacheId}");
     ProductSpecial::model()->deleteAll("product_id={$this->cacheId}");
     ProductToCategory::model()->deleteAll("product_id={$this->cacheId}");
     ProductToDownload::model()->deleteAll("product_id={$this->cacheId}");
     ProductToLayout::model()->deleteAll("product_id={$this->cacheId}");
     ProductToStore::model()->deleteAll("product_id={$this->cacheId}");
     Review::model()->deleteAll("product_id={$this->cacheId}");
     UrlAlias::model()->deleteAll("query='product_id={$this->cacheId}'");
     parent::afterDelete();
 }
예제 #5
0
 public function actionDelete($id)
 {
     $this->loadModel($id)->delete();
     ProductDescription::model()->deleteAll('product_id=' . $id);
     Category2product::model()->deleteAll('product_id=' . $id);
     $aVariations = Product2variation::model()->findAll('product_id=' . $id);
     foreach ($aVariations as $variation) {
         Variation::model()->deleteAll('variation_id=' . $variation['variation_id']);
         VariationDescription::model()->deleteAll('variation_id=' . $variation['variation_id']);
         Variation2attribute::model()->deleteAll('variation_id=' . $variation['variation_id']);
         Variation2value::model()->deleteAll('variation_id=' . $variation['variation_id']);
     }
     Product2variation::model()->deleteAll('product_id=' . $id);
     // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
     if (!isset($_GET['ajax']))
       $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
 }
예제 #6
0
 public function actionPDF()
 {
     $session = new CHttpSession();
     $session->open();
     if (isset($session['orderVariations']) && is_array($session['orderVariations']) && count($session['orderVariations']) > 0) {
         require_once Yii::getPathOfAlias('webroot.protected.extensions.pdf.tcpdf') . DIRECTORY_SEPARATOR . 'tcpdf.php';
         $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
         $aOrderVariations = $session['orderVariations'];
         $html_output = '<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><table>';
         $html_output .= '<tr><td colspan="3"></td></tr>';
         $html_output .= '<tr><td colspan="3">' . Yii::t('strings', 'Order products:') . "</td></tr>";
         $html_output .= '<tr><td colspan="3"></td></tr>';
         foreach ($aOrderVariations as $variation_id) {
             $Product2variation = Product2variation::model()->find('variation_id=' . $variation_id);
             if (isset($Product2variation)) {
                 $product = ProductDescription::model()->find('product_id=' . $Product2variation['product_id'] . ' AND language_id=' . $this->language_id);
                 $Variation = Variation::model()->find('variation_id=' . $variation_id);
                 $VariationDescription = VariationDescription::model()->find('variation_id=' . $variation_id . ' AND language_id=' . $this->language_id);
                 $html_output .= '<tr><td colspan="3">' . $product['product_name'] . '</td></tr>';
                 $html_output .= '<tr><td><img src="' . Yii::app()->request->getBaseUrl(true) . '/uploads/images/' . $Variation['variation_image'] . '" alt="product_image" width="100" height="50"/></td>';
                 $html_output .= '<td>' . $VariationDescription['variation_name'] . '<br/>' . $VariationDescription['variation_description'] . "</td></tr>";
                 $html_output .= '<tr><td colspan="3"></td><td></td></tr>';
             }
         }
         $html_output .= '</table></body></html>';
         $pdf->SetHeaderData(PDF_HEADER_LOGO, '', '', '', array(0, 64, 255), array(169, 172, 182));
         $pdf->setFooterData($tc = array(0, 64, 0), $lc = array(0, 64, 128));
         $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
         $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
         $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
         $pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);
         $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
         $pdf->setLanguageArray($l);
         $pdf->setFontSubsetting(true);
         $pdf->SetFont('dejavusans', '', 14, '', true);
         $pdf->AddPage();
         $pdf->setTextShadow(array('enabled' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 1, 'blend_mode' => 'Normal'));
         $pdf->writeHTMLCell($w = 0, $h = 0, $x = '', $y = '', $html_output, $border = 0, $ln = 1, $fill = 0, $reseth = true, $align = 'L', $autopadding = true);
         $pdf->Output('order.pdf', 'I');
     }
 }
예제 #7
0
 public function save()
 {
     $product = Product::model()->findByPk($this->id);
     if (is_null($product)) {
         // insert
         // Product
         $product = new Product();
         $product->model = $this->model;
         $product->sku = $this->sku;
         $product->upc = $this->upc;
         $product->ean = $this->ean;
         $product->jan = $this->jan;
         $product->isbn = $this->isbn;
         $product->mpn = $this->mpn;
         $product->location = $this->location;
         $product->price = $this->price;
         $product->tax_class_id = $this->taxClass;
         $product->quantity = $this->quantity;
         $product->minimum = $this->minimumQuantity;
         $product->subtract = $this->subtractStock;
         $product->stock_status_id = $this->outOfStockStatus;
         $product->shipping = $this->requiresShipping;
         $product->image = $this->image;
         $product->date_available = $this->dateAvailable;
         $product->length = $this->dimensionL;
         $product->height = $this->dimensionH;
         $product->width = $this->dimensionW;
         $product->weight = $this->weight;
         $product->weight_class_id = $this->weightClass;
         $product->sort_order = $this->sortOrder;
         $product->status = $this->status;
         $product->manufacturer_id = $this->manufacturer;
         $product->save();
         // Description
         $description = new ProductDescription();
         $description->product_id = $product->product_id;
         $description->language_id = 1;
         // TODO: make this dynamic
         $description->name = $this->name;
         $description->meta_description = $this->metaTagDescription;
         $description->meta_keyword = $this->metaTagKeywords;
         $description->description = $this->description;
         $description->tag = $this->productTags;
         $description->save();
     } else {
         // update
         // Product
         $product->model = $this->model;
         $product->sku = $this->sku;
         $product->upc = $this->upc;
         $product->ean = $this->ean;
         $product->jan = $this->jan;
         $product->isbn = $this->isbn;
         $product->mpn = $this->mpn;
         $product->location = $this->location;
         $product->price = $this->price;
         $product->tax_class_id = $this->taxClass;
         $product->quantity = $this->quantity;
         $product->minimum = $this->minimumQuantity;
         $product->subtract = $this->subtractStock;
         $product->stock_status_id = $this->outOfStockStatus;
         $product->shipping = $this->requiresShipping;
         $product->image = $this->image;
         $product->date_available = $this->dateAvailable;
         $product->length = $this->dimensionL;
         $product->height = $this->dimensionH;
         $product->width = $this->dimensionW;
         $product->weight = $this->weight;
         $product->weight_class_id = $this->weightClass;
         $product->sort_order = $this->sortOrder;
         $product->status = $this->status;
         $product->manufacturer_id = $this->manufacturer;
         $product->save();
         // Description
         $product->description->name = $this->name;
         $product->description->meta_description = $this->metaTagDescription;
         $product->description->meta_keyword = $this->metaTagKeywords;
         $product->description->description = $this->description;
         $product->description->tag = $this->productTags;
         $product->description->save();
     }
     // SEO Keyword
     $product->updateSEOKeyword($this->seoKeyword);
     // Filters
     $product->clearAllFiltersRelations();
     if (isset($this->filters) && count($this->filters) > 0) {
         foreach ($this->filters as $filterId) {
             $product->addFilter($filterId);
         }
     }
     // Categories
     $product->clearAllCategoriesRelations();
     if (isset($this->categories) && count($this->categories)) {
         foreach ($this->categories as $categoryId) {
             $product->addToCategory($categoryId);
         }
     }
     // Stores
     $product->clearAllStoresRelations();
     if (isset($this->stores) && count($this->stores)) {
         foreach ($this->stores as $storeId) {
             $product->addToStore($storeId);
         }
     }
     // Downloads
     $product->clearAllDownloadsRelations();
     if (isset($this->downloads) && count($this->downloads)) {
         foreach ($this->downloads as $downloadId) {
             $product->addToDownload($downloadId);
         }
     }
     // Related Products
     $product->clearAllRelatedProductsRelations();
     if (isset($this->relatedProducts) && count($this->relatedProducts)) {
         foreach ($this->relatedProducts as $relatedId) {
             $product->addRelatedProduct($relatedId);
         }
     }
 }
예제 #8
0
 public static function fixProductNames()
 {
     $products = Product::find_many();
     foreach ($products as $product) {
         $description = ProductDescription::find_one($product->product_id);
         if (strpos($description->name, $product->sku) != -1) {
             $description->name = rtrim(str_replace($product->sku, '', $description->name));
             $description->save();
             self::$debug['messages']->info($description->name);
         }
     }
 }