/**
  * @param string  $sku
  * @param Request $request
  *
  * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function putProductCategory(string $sku, Request $request)
 {
     /** @var Product $product */
     $product = $this->product->where('sku', '=', $sku)->firstOrFail();
     $category = $this->category->findOrFail($request->get('category-id'));
     $product->category()->associate($category);
     $product->save();
     $this->webUi->successMessage("Set category for `{$product->sku}` to `{$category->name}`.");
     return $this->webUi->redirect('products.show', [$product->sku]);
 }
Esempio n. 2
0
 /**
  * @param string $sku
  * @param int    $units
  * @param int    $subunits
  *
  * @return bool
  */
 public function setPriceBySku(string $sku, int $units, int $subunits)
 {
     /** @var Product $product */
     $product = $this->productResource->where('sku', $sku)->with('prices')->limit(1)->first();
     $price = $product->prices()->firstOrNew([]);
     $price->setAttribute('units', $units);
     $price->setAttribute('subunits', $subunits);
     $price->setAttribute('currency', 'GBP');
     return $price->save();
 }
Esempio n. 3
0
 /**
  * Should be able to set a product's tags from its view page.
  */
 public function testCanSetTagsForProductFromProductView()
 {
     $tag = $this->createTag();
     $product = $this->createProduct();
     $productView = route('products.show', ['sku' => $product->sku]);
     $this->actingAs($this->staffUser())->visit($productView)->seePageIs($productView)->select($tag->id, 'tag-ids')->press('Save tags')->see('Tags updated');
     $tagOption = $this->crawler()->filter("#tag-option-{$tag->id}");
     $this->assertEquals($tagOption->attr('selected'), 'selected');
     $product = Product::where('id', '=', $product->id)->with('tags')->first();
     $this->assertContains($tag->id, $product->tags->pluck('id'));
 }
Esempio n. 4
0
 /**
  * @param Request $request
  * @param string  $sku
  *
  * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function putProductOffers(Request $request, string $sku)
 {
     $product = Product::where('sku', '=', $sku)->firstOrFail();
     $product->offers()->sync((array) $request->get('offer-ids'));
     $this->webUi->successMessage("Set offers for product `{$product->sku}`.");
     return $this->webUi->redirect('products.show', ['sku' => $sku]);
 }