/**
  * Should be able to set the price by SKU.
  */
 public function testSetPriceBySku()
 {
     $product = $this->makeMock(Product::class);
     $this->productResource->shouldReceive('where->with->limit->first')->atLeast()->once()->andReturn($product);
     $prices = $this->makeMock(HasMany::class);
     $price = $this->makeMock(Price::class);
     $product->expects($this->atLeastOnce())->method('prices')->willReturn($prices);
     $prices->expects($this->atLeastOnce())->method('firstOrNew')->willReturn($price);
     $units = 5;
     $subunits = 99;
     $price->expects($this->atLeastOnce())->method('setAttribute')->withConsecutive(['units', $units], ['subunits', $subunits], ['currency', 'GBP']);
     $price->expects($this->atLeastOnce())->method('save');
     $this->productRepository->setPriceBySku('foo sku', $units, $subunits);
 }
Exemplo n.º 2
0
 /**
  * @param string          $sku
  * @param SetPriceRequest $setPriceRequest
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function setProductPrice(string $sku, SetPriceRequest $setPriceRequest)
 {
     $this->productRepository->setPriceBySku($sku, $setPriceRequest->get('units'), $setPriceRequest->get('subunits'));
     return $this->webUi->redirect('products.show', [$sku]);
 }