Skip to content

Commit cb5129a

Browse files
authored
Merge pull request #1022 from w3bdesign/1021-show-stock-status-in-product
1021 show stock status in product
2 parents a10aad4 + f7b373c commit cb5129a

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

apollo/queries/GET_SINGLE_PRODUCT_QUERY.gql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ query Product($id: ID!) {
1818
salePrice
1919
regularPrice
2020
databaseId
21+
stockQuantity
2122
}
2223
... on VariableProduct {
2324
price

components/Products/ProductsSingleProduct.vue

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
<p class="pt-1 mt-4 text-2xl text-gray-900">
4545
{{ stripHTML(data.product.description) }}
4646
</p>
47+
<p
48+
v-if="data.product.stockQuantity"
49+
class="pt-1 mt-4 text-2xl text-gray-900"
50+
>
51+
{{ data.product.stockQuantity }} in stock
52+
</p>
4753
<p
4854
v-if="data.product.variations"
4955
class="pt-1 mt-4 text-xl text-gray-900"
@@ -60,7 +66,8 @@
6066
:value="variation.databaseId"
6167
:selected="index === 0"
6268
>
63-
{{ variation.name }}
69+
{{ filteredVariantName(data.product.name, variation.name) }}
70+
({{ variation.stockQuantity }} in stock)
6471
</option>
6572
</select>
6673
</p>
@@ -83,7 +90,11 @@
8390
import GET_SINGLE_PRODUCT_QUERY from "@/apollo/queries/GET_SINGLE_PRODUCT_QUERY.gql";
8491
import ADD_TO_CART_MUTATION from "@/apollo/mutations/ADD_TO_CART_MUTATION.gql";
8592
86-
import { stripHTML, filteredVariantPrice } from "@/utils/functions";
93+
import {
94+
stripHTML,
95+
filteredVariantPrice,
96+
filteredVariantName,
97+
} from "@/utils/functions";
8798
8899
import { useCart } from "@/store/useCart";
89100

utils/functions.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ export const filteredVariantPrice = (price, side) => {
2020
return price.substring(0, price.indexOf("-")).replace("-", "");
2121
};
2222

23+
/**
24+
* Strips product name from variant name
25+
* @param {String} productName Text to strip out
26+
* @param {String} input Input text to strip product name from
27+
*/
28+
export function filteredVariantName(productName, input) {
29+
return input.replace(`${productName} -`, "");
30+
}
31+
2332
/**
2433
* Prepares the checkout object based on the input data from the checkout form
2534
* @param {Object} form Form data to process

0 commit comments

Comments
 (0)