Skip to content

Commit

Permalink
feature #503 Add onHand to product response (alexander-schranz)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.0-dev branch.

Discussion
----------

It should be possible to know how many products are still available.

Commits
-------

168ca19 Add onHand to product response
  • Loading branch information
mamazu authored Jul 31, 2019
2 parents 3e49756 + 168ca19 commit d4ebf04
Show file tree
Hide file tree
Showing 46 changed files with 123 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,9 @@ definitions:
type: "object"
additionalProperties:
type: "string"
onHand:
type: "integer"
example: 12
price:
$ref: "#/definitions/Price"
images:
Expand Down
2 changes: 2 additions & 0 deletions spec/Factory/Product/ProductVariantViewFactorySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function it_builds_product_variant_view(
$variantView = new ProductVariantView();

$variant->getCode()->willReturn('SMALL_RED_LOGAN_HAT_CODE');
$variant->getOnHand()->willReturn(12);
$variant->getTranslation('en_GB')->willReturn($productVariantTranslation);
$variant->getChannelPricingForChannel($channel)->willReturn($channelPrice);
$variant->getOptionValues()->willReturn(new ArrayCollection([
Expand Down Expand Up @@ -85,6 +86,7 @@ function it_builds_product_variant_view(
$variantView->name = 'Small red Logan hat code';
$variantView->price = new PriceView();
$variantView->axis = ['HAT_SIZE_S', 'HAT_COLOR_RED'];
$variantView->onHand = 12;
$variantView->nameAxis = [
'HAT_SIZE_S' => 'Size S',
'HAT_COLOR_RED' => 'Color Red',
Expand Down
1 change: 1 addition & 0 deletions src/Factory/Product/ProductVariantViewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function create(ProductVariantInterface $variant, ChannelInterface $chann

$variantView->code = $variant->getCode();
$variantView->name = $variant->getTranslation($locale)->getName();
$variantView->onHand = $variant->getOnHand();
$variantView->price = $this->priceViewFactory->create(
$channelPricing->getPrice(),
$channel->getBaseCurrency()->getCode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Sylius\ShopApiPlugin\View\Product\ProductVariantView:
nameAxis:
expose: true
type: array<string, string>
onHand:
expose: true
type: int
price:
expose: true
type: Sylius\ShopApiPlugin\View\PriceView
Expand Down
3 changes: 3 additions & 0 deletions src/View/Product/ProductVariantView.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class ProductVariantView
/** @var array */
public $nameAxis = [];

/** @var int */
public $onHand;

/** @var PriceView */
public $price;

Expand Down
1 change: 1 addition & 0 deletions tests/DataFixtures/ORM/shop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Sylius\Component\Core\Model\ProductVariant:
product: "@mug"
currentLocale: "en_GB"
translations: ["@en_gb_mug_variant_translation", "@de_de_mug_variant_translation"]
onHand: 12
channelPricings:
WEB_GB: "@gb_mug_web_channel_pricing"
WEB_DE: "@de_mug_web_channel_pricing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"name": "Logan Mug",
"axis": [],
"nameAxis": {},
"onHand": 12,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down Expand Up @@ -81,6 +82,7 @@
"name": "Small Logan T-Shirt",
"axis": [],
"nameAxis": {},
"onHand": 0,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down Expand Up @@ -141,6 +143,7 @@
"HAT_SIZE_S": "Size S",
"HAT_COLOR_RED": "Color Red"
},
"onHand": 0,
"price": {
"current": 500,
"currency": "GBP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"name": "Logan Mug",
"axis": [],
"nameAxis": {},
"onHand": 12,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down Expand Up @@ -81,6 +82,7 @@
"name": "Small Logan T-Shirt",
"axis": [],
"nameAxis": {},
"onHand": 0,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down Expand Up @@ -141,6 +143,7 @@
"HAT_SIZE_S": "Size S",
"HAT_COLOR_RED": "Color Red"
},
"onHand": 0,
"price": {
"current": 500,
"currency": "GBP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"HAT_SIZE_S": "Size S",
"HAT_COLOR_RED": "Color Red"
},
"onHand": 0,
"price": {
"current": 500,
"currency": "GBP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"HAT_SIZE_S": "Size S",
"HAT_COLOR_RED": "Color Red"
},
"onHand": 0,
"price": {
"current": 500,
"currency": "GBP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"name": "Small Logan T-Shirt",
"axis": [],
"nameAxis": {},
"onHand": 0,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"name": "Small Logan T-Shirt",
"axis": [],
"nameAxis": {},
"onHand": 0,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"name": "Logan Mug",
"axis": [],
"nameAxis": {},
"onHand": 12,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"name": "Logan Mug",
"axis": [],
"nameAxis": {},
"onHand": 12,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"name": "Logan Mug",
"axis": [],
"nameAxis": {},
"onHand": 12,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"name": "Logan Mug",
"axis": [],
"nameAxis": {},
"onHand": 12,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"name": "Small Logan T-Shirt",
"axis": [],
"nameAxis": {},
"onHand": 0,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down Expand Up @@ -89,6 +90,7 @@
"HAT_SIZE_S": "Size S",
"HAT_COLOR_RED": "Color Red"
},
"onHand": 0,
"price": {
"current": 500,
"currency": "GBP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"name": "Logan Mug",
"axis": [],
"nameAxis": {},
"onHand": 12,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"HAT_SIZE_S": "Size S",
"HAT_COLOR_RED": "Farbe Rot"
},
"onHand": 0,
"price": {
"current": 590,
"currency": "EUR"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"name": "Logan Becher",
"axis": [],
"nameAxis": {},
"onHand": 12,
"price": {
"current": 2099,
"currency": "EUR"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"name": "Logan Mug",
"axis": [],
"nameAxis": {},
"onHand": 12,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"name": "Logan Mug",
"axis": [],
"nameAxis": {},
"onHand": 12,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"name": "Logan Mug",
"axis": [],
"nameAxis": {},
"onHand": 12,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"name": "Logan Mug",
"axis": [],
"nameAxis": {},
"onHand": 12,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"name": "Logan Mug",
"axis": [],
"nameAxis": {},
"onHand": 12,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"name": "Logan Mug",
"axis": [],
"nameAxis": {},
"onHand": 12,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"name": "Logan Mug",
"axis": [],
"nameAxis": {},
"onHand": 12,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"name": "Logan Mug",
"axis": [],
"nameAxis": {},
"onHand": 12,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down
1 change: 1 addition & 0 deletions tests/Responses/Expected/order/order_details_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"name": "Logan Mug",
"axis": [],
"nameAxis": {},
"onHand": 12,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"name": "Logan Mug",
"axis": [],
"nameAxis": {},
"onHand": 12,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down
1 change: 1 addition & 0 deletions tests/Responses/Expected/order/orders_list_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"name": "Logan Mug",
"axis": [],
"nameAxis": {},
"onHand": 12,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"name": "Logan Becher",
"axis": [],
"nameAxis": {},
"onHand": 12,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down Expand Up @@ -87,6 +88,7 @@
"HAT_SIZE_S": "Size S",
"HAT_COLOR_RED": "Farbe Rot"
},
"onHand": 0,
"price": {
"current": 500,
"currency": "GBP"
Expand All @@ -104,6 +106,7 @@
"HAT_SIZE_L": "Size L",
"HAT_COLOR_RED": "Farbe Rot"
},
"onHand": 0,
"price": {
"current": 999,
"currency": "GBP"
Expand All @@ -121,6 +124,7 @@
"HAT_SIZE_S": "Size S",
"HAT_COLOR_BLUE": "Farbe Blau"
},
"onHand": 0,
"price": {
"current": 1500,
"currency": "GBP"
Expand All @@ -138,6 +142,7 @@
"HAT_SIZE_L": "Size L",
"HAT_COLOR_BLUE": "Farbe Blau"
},
"onHand": 0,
"price": {
"current": 2599,
"currency": "GBP"
Expand Down Expand Up @@ -167,6 +172,7 @@
"name": "Logan Becher",
"axis": [],
"nameAxis": {},
"onHand": 12,
"price": {
"current": 1999,
"currency": "GBP"
Expand Down Expand Up @@ -219,6 +225,7 @@
"name": "Small Logan T-Shirt",
"axis": [],
"nameAxis": {},
"onHand": 0,
"price": {
"current": 1999,
"currency": "GBP"
Expand All @@ -235,6 +242,7 @@
"name": "Large Logan T-Shirt",
"axis": [],
"nameAxis": {},
"onHand": 0,
"price": {
"current": 2999,
"currency": "GBP"
Expand Down
Loading

0 comments on commit d4ebf04

Please sign in to comment.