本文整理汇总了PHP中app\models\Product类的典型用法代码示例。如果您正苦于以下问题:PHP Product类的具体用法?PHP Product怎么用?PHP Product使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Product类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionPayment
public function actionPayment()
{
if (\Yii::$app->session->has('customer')) {
$modelCustomer = new Customer();
$infoCustomer = $modelCustomer->getInformation($_SESSION['customer']);
$modelOrder = new Order();
$modelOrderDetail = new OrderDetail();
$modelProduct = new Product();
$ids = array();
foreach ($_SESSION['cart_items'] as $id => $quantity) {
array_push($ids, $id);
}
$products = $modelProduct->getWithIDs($ids);
if (\Yii::$app->request->post()) {
$modelOrder->load(\Yii::$app->request->post());
$modelOrder->save();
$orderId = $modelOrder->id;
foreach ($_SESSION['cart_items'] as $id => $quantity) {
$unitPrice = $modelProduct->getPrice($id) * $quantity;
\Yii::$app->db->createCommand()->insert('order_detail', ['orderId' => $orderId, 'productId' => $id, 'unitPrice' => $unitPrice, 'quantity' => $quantity])->execute();
}
\Yii::$app->session->remove('cart_items');
return $this->redirect(['cart/index', 'success' => 'Thanh toán thành công! Chúng tôi sẽ liên hệ bạn trong thời gian sớm nhất! Xin cảm ơn!']);
} else {
return $this->render('payment', ['infoCustomer' => $infoCustomer, 'modelOrder' => $modelOrder, 'products' => $products]);
}
} else {
$this->redirect(['customer/login', 'error' => 'Vui lòng đăng nhập trước khi thanh toán']);
}
}
示例2: updatingListProducts
public function updatingListProducts($data)
{
//pr($data);
$productModel = new Product();
foreach ($data as $key => &$element) {
if (isset($element['GK.site_id'])) {
$check = $productModel->comparePrice('GK', $key, isset($element['GK.enabled']) ? $element['GK.enabled'] : null, isset($element['GK.yandex_enabled']) ? $element['GK.yandex_enabled'] : null, isset($element['GK.price']) ? addComma($element['GK.price']) : null, isset($element['GK.currency']) ? $element['GK.currency'] : null);
if ($check) {
$element['GK.to_export'] = 1;
}
}
if (isset($element['TV.site_id'])) {
$check = $productModel->comparePrice('TV', $key, isset($element['TV.enabled']) ? $element['TV.enabled'] : null, isset($element['TV.yandex_enabled']) ? $element['TV.yandex_enabled'] : null, isset($element['TV.price']) ? addComma($element['TV.price']) : null, isset($element['TV.currency']) ? $element['TV.currency'] : null);
if ($check) {
$element['TV.to_export'] = 1;
}
}
if (isset($element['MK.site_id'])) {
$check = $productModel->comparePrice('MK', $key, isset($element['MK.enabled']) ? $element['MK.enabled'] : null, isset($element['MK.yandex_enabled']) ? $element['MK.yandex_enabled'] : null, isset($element['MK.price']) ? addComma($element['MK.price']) : null, isset($element['MK.currency']) ? $element['MK.currency'] : null);
if ($check) {
$element['MK.to_export'] = 1;
}
}
$this->leftJoin('price_GK as GK', 'products.id', '=', 'GK.product_id')->leftJoin('price_TV as TV', 'products.id', '=', 'TV.product_id')->leftJoin('price_MK as MK', 'products.id', '=', 'MK.product_id')->where('products.id', $key)->update($element);
}
/*pr($data,true);*/
}
示例3: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$pro = new Product();
$adSlotObj = new Adslot();
$catObj = new Category();
$brandObj = new Brand();
/*getting all products for all slots(currently we have 7 slots)*/
$adSlot_data = $adSlotObj->with(['products'])->get();
/*t1-t7*/
// dd($adSlot_data[4]['products'][0]);
$category_temp_data = $catObj->orderBy('created_at')->take(10)->get();
/*f1-f10*/
$brand_data = $brandObj->with(['products'])->get();
$category_data = [];
foreach ($category_temp_data as $cat_id) {
$cat_latest_product = $pro->where('category_id', '=', $cat_id['id'])->orderBy('created_at')->take(1)->pluck('photo_1');
$cat_latest_product_id = $pro->where('category_id', '=', $cat_id['id'])->orderBy('created_at')->take(1)->pluck('id');
$cat_random_product = $pro->where('category_id', '=', $cat_id['id'])->orderBy(DB::raw('RAND()'))->take(6)->get();
$cat_brands = $pro->with(['brand'])->where('category_id', '=', $cat_id['id'])->take(5)->get();
$cat_products_random_photos = [];
foreach ($cat_random_product as $photo) {
$cat_products_random_photos[] = $photo;
}
$category_data[] = ['color' => $cat_id['color'], 'floor' => $cat_id['floor'], 'name' => $cat_id['name'], 'desc' => $cat_id['description'], 'logo' => $cat_id['logo'], 'latest_photo_id' => $cat_latest_product_id, 'latest_photo' => $cat_latest_product, 'random_photos' => $cat_products_random_photos, 'brands' => $cat_brands];
}
return view('landing_page', compact(['adSlot_data', 'category_data']));
}
示例4: setUp
public function setUp()
{
parent::setUp();
$this->shared('product', function () {
$product = new Product(["product_name" => "iPhone 6", "product_desc" => "iPhone 6", "status" => "available", "options" => [["name" => "颜色", "options" => ["深空灰", "银色", "金色"]], ["name" => "容量", "options" => ["16GB", "64GB", "128GB"]]], "specifications" => [["attr_name" => "高度", "attr_group" => "重量和尺寸", "attr_value" => "138.1 毫米(5.44 英寸)"], ["attr_name" => "宽度", "attr_group" => "重量和尺寸", "attr_value" => "67.0 毫米 (2.64 英寸)"], ["attr_name" => "厚度", "attr_group" => "重量和尺寸", "attr_value" => "6.9 毫米 (0.27 英寸)"], ["attr_name" => "重量", "attr_group" => "重量和尺寸", "attr_value" => "129 克 (4.55 盎司)"]]]);
$product->save();
return $product;
});
}
示例5: actionIndex
public function actionIndex()
{
$product = new Product('jielun', 50);
print_r($product->getProductName());
print_r('<br>---------------<br>');
$cdProduct = new CdProduct('jay', 20);
print_r($cdProduct->getProductName());
//print_r($cdProduct->getAddress()); //子类无法使用parent::$address访问父类的私有属性
}
示例6: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Product $product, Request $request)
{
if ($request->ajax()) {
$request = $request->all();
$products = $product->filter($request, $this->itemsCount);
$i = 1;
return view('admin._response.products-index')->with('products', $products)->with('i', $i);
}
}
示例7: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(UpdateProductRequest $request, Product $product)
{
$data = $request->input();
$product->fill($data);
$product->save();
$this->savePhoto($product, $request);
$product->categories()->detach($product->categories()->lists('id')->toArray());
$product->categories()->attach($data['categories']);
return Redirect()->route('home');
}
示例8: findModel
public function findModel($id)
{
$search = new Product();
$search->scenario = Product::SCENARIO_READ;
if (($model = $search->findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
示例9: buildFromInput
protected function buildFromInput(Product $product, $input)
{
$title = $input->get('title');
// #TODO: Shouldn't really be optional
$imageUrl = $input->has('image_url') ? $input->get('image_url') : null;
$product->setTitle($title);
$product->setImageUrl($imageUrl);
EntityManager::persist($product);
EntityManager::flush();
return $product;
}
示例10: show
public function show($cat, $prod = '')
{
!preg_match("|^[a-z0-9]+\$|", $cat) && exit;
$prod && !preg_match("|^[a-z0-9]+\$|", $prod) && exit;
$product = new Product();
$view = new View();
$cat && ($result = $product->showCatalog($cat, $prod)) ? $view->display($result, $cat) : (($result = $product->showProduct($prod)) ? $view->display($result, 'prod') : ($this->error = true));
if ($this->error) {
throw new Exception('Что то пошло не так... Скорее всего таблица пуста!');
}
}
示例11: deleteProduct
public function deleteProduct(Product $product)
{
event(new DeleteUnpublishedNotification($product->barcode));
if ($product->countOrganizations == 1) {
$product->delete();
} else {
$product->organizations()->detach($this->user->organization->id);
}
flash()->info('Διεγράφη', 'το συγκεκριμένο προϊόν διεγράφη με επιτυχία από τον Οργανισμό');
return redirect()->route('Admin::Unpublished::index');
}
示例12: actionSearchProducts
public function actionSearchProducts()
{
$modelForm = new Product();
$results = null;
if ($modelForm->load(Yii::$app->request->post())) {
$results = $modelForm->giveAllProductsByName($modelForm->name);
Yii::$app->session->setFlash('contactFormSubmitted');
return $this->render('searchProducts', ['modelForm' => $modelForm, 'results' => $results]);
} else {
return $this->render('searchProducts', ['modelForm' => $modelForm, 'results' => $results]);
}
}
示例13: fakeProduct
protected function fakeProduct()
{
$fakeProduct = new Product();
$fakeProduct->serial_number = "P1284724";
$fakeProduct->primary_name = "Fake Product";
$fakeProduct->product_type_id = $this->fakeProductType()->product_type_id;
$fakeProduct->currency_id = $this->fakeCurrency()->currency_id;
$fakeProduct->client_id = $this->fakeClient()->client_id;
$fakeProduct->supplier_id = $this->fakeSupplier()->supplier_id;
$fakeProduct->save();
return $fakeProduct;
}
示例14: actionProduct
public function actionProduct($id)
{
$modelProduct = new Product();
foreach ($modelProduct->getProduct($id) as $product) {
$idProduct = $product['id'];
$nameProduct = $product['name'];
$typeProduct = $product['type'];
$priceProduct = $product['price'];
$descriptionProduct = $product['description'];
$imageProduct = $product['image'];
}
return $this->render('product', ['idProduct' => $idProduct, 'nameProduct' => $nameProduct, 'typeProduct' => $typeProduct, 'priceProduct' => $priceProduct, 'descriptionProduct' => $descriptionProduct, 'imageProduct' => $imageProduct]);
}
示例15: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Request $request)
{
$product = new Product();
$product->name = $request->input('name');
$product->price = $request->input('price');
$product->description = $request->input('description');
$product->save();
for ($i = 0; $i < $request->input('stock'); $i++) {
$item = new ProductItem();
$item->code = date('YmdHis') . '.' . $i;
$item = $product->item()->save($item);
}
}