public function shortSearch($params) { $query = Product::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['like', 'sku', $this->sku])->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
public function getProduct() { return $this->hasOne(Product::className(), ['sku' => 'item_sku']); }
/** * Finds the Product model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Product the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Product::findOne($id)) !== null && Yii::$app->user->can('ebaycontrol', ['userID' => $model->user_id])) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<?php use yii\jui\AutoComplete; use frontend\models\products\Product; ?> <div class="row"> <div class="col-xs-12 col-sm-8"> <div class="input-group"> <span class="input-group-addon"> <i class="ace-icon fa fa-cube"></i> </span> <?php $this->registerCss('.ui-autocomplete{z-index:1060}'); $mainSKUs = Product::find()->where(['is not', 'stock_qty', null])->andWhere(['qty_per_order' => 1])->asArray()->indexBy('sku')->all(); echo AutoComplete::widget(['name' => 'main-sku', 'clientOptions' => ['source' => array_keys($mainSKUs)], 'options' => ['class' => 'form-control search-query', 'placeholder' => 'Put the main product SKU', 'id' => 'main-sku']]); ?> <span class="input-group-btn"> <button type="button" class="btn btn-purple btn-sm" id="link-product"> <span class="ace-icon fa fa-link icon-on-right bigger-110"></span> Link </button> </span> </div> </div> </div>
public function actionReviseOneItem() { if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; $post = Yii::$app->request->post(); $ebayListing = new EbayListing($post['ebayID']); $listing = Listing::find()->where(['item_id' => $post['itemID']])->one(); if ($listing == null) { return false; } $listingItem = new ApiListingItem(); $listingItem->item_id = $listing->item_id; $listingItem->title = $post['title']; $listingItem->qty = $post['qty']; $listingItem->price = $post['price']; $listingItem->shippingCost = $post['shipping']; $listingItem->shippingExpressCost = $post['expressShipping']; $product = Product::findOne(['sku' => $listing->sku]); $ebayAccount = EbayAccount::findOne($post['ebayID']); $lstImages = ListingImages::findOne(['product_id' => $product->id, 'ebay_account_id' => $post['ebayID']]); $listingImages = ['http://i.imgur.com/roXpiR8.png']; if ($lstImages) { $listingImages = json_decode($lstImages->image_url); } $listingItem->description = $this->renderFile(Yii::$app->params['listingTemplatePath'] . $ebayAccount->listingTemplate->name . '.php', ['ebayAcc' => $ebayAccount, 'product' => $product, 'lstImages' => $listingImages]); $result = $ebayListing->reviseItem($listingItem); if (isset($result['itemID']) && !isset($result['error'])) { $result['status'] = 'success'; $result['message'] = "Item: " . $result['itemID'] . " revised"; } else { $result['status'] = 'failed'; $result['message'] = "Item: " . $result['itemID'] . " NOT revised"; } return $result; } else { return false; } }
/** * @return \yii\db\ActiveQuery */ public function getSub0() { return $this->hasOne(Product::className(), ['id' => 'sub']); }
public function scenarios() { $scenarios = parent::scenarios(); $scenarios['batch'] = ['sku', 'mini_desc', 'name', 'weight', 'description', 'specs', 'comment', 'supplier_id', 'is_trackable', 'stock_location', 'cost', 'category_id', 'qty_per_order', 'main_image']; return $scenarios; }