Enable article barcode scanning
Author:
Fluent Commerce
Changed on:
19 Jan 2024
Key Points
- Working with barcodes
Author:
Fluent Commerce
Changed on:
19 Jan 2024
1{{fluentApiHost}}/api/v4.1/article?retailerId={{retailer_id}}&query={{article_barcode}}&status=COURIER_COLLECTION&status=CUSTOMER_COLLECTION&fulfilmentStatus=FULFILLED&fulfilmentStatus=PARTIALLY_FULFILLED&type=CFS&type=CC_PFDC&type=CC_PFS&count=10&direction=INBOUND1context.action().addBarcode(articleEntity, ``"ARTICLE_BARCODE"``, ``"123"``);1 {{fluentApiHost}}/api/v4.``1``/article/{{articleId}}/barcode1{
2 ``"barcode"``:``"123"``, ``//scannable barcode
3 ``"barcodeType"``:``"ARTICLE_BARCODE"` `//a type. e.g. REWARDS_CARD, ARTICLE_BARCODE, ...
4}1package` `com.fluentretail.rubix.foundation.rule;
2import` `com.fluentretail.api.model.BarcodeReferencableEntity;
3import` `com.fluentretail.api.model.article.Article;
4import` `com.fluentretail.api.model.attribute.Attribute;
5import` `com.fluentretail.rubix.context.Context;
6import` `com.fluentretail.rubix.rule.Rule;
7import` `com.fluentretail.rubix.rule.meta.ParamString;
8import` `com.fluentretail.rubix.rule.meta.RuleInfo;
9import` `com.fluentretail.rubix.util.RuleUtils;
10import` `lombok.extern.slf4j.Slf4j;
11import` `java.util.List;
12import` `static` `com.fluentretail.rubix.util.RuleUtils.validateSupportedType;
13/**
14 ``*
15 ``*/
16@RuleInfo``(
17 ``name = ``"AddArticleBarcodeFromOrderAttributes"``,
18 ``description = ``"Add Article Barcode from the Order Attributes <attributeNames> "``,
19 ``produces = {}
20)
21@ParamString``(
22 ``name = AddArticleBarcodeFromOrderAttributes.PROP_ATTRIBUTE_NAMES,
23 ``description = ``"Name of the attributes to create Barcode from"
24)
25@Slf4j
26public` `class` `AddArticleBarcodeFromOrderAttributes ``implements` `Rule {
27
28 ``public` `static` `final` `String PROP_ATTRIBUTE_NAMES = ``"attributeNames"``;
29
30 ``@Override
31 ``public` `void` `run(Context context) {
32 ``RuleUtils.validateRuleProps(context, PROP_ATTRIBUTE_NAMES);
33 ``BarcodeReferencableEntity entity = validateSupportedType(context.getEntity(), BarcodeReferencableEntity.``class``);
34 ``List<String> attributeNames = context.getPropList(PROP_ATTRIBUTE_NAMES, String.``class``);
35
36 ``Article articleResponse = context.api().getArticle(entity.getId());
37 ``String orderId = articleResponse.getOrderId();
38 ``Attribute.List entityAttributesResponse = context.api().getOrderAttributes(orderId);
39 ``entityAttributesResponse.getAttributes().forEach(attribute -> attributeNames.forEach(attributeName -> {
40 ``if` `(attributeName.equals(attribute.getName())) {
41 ``context.action().addBarcode(entity, attribute.getName(), (String) attribute.getValue());
42 ``}
43 ``}));
44 ``}
45}1{
2 "name": "FLUENTRETAIL.base.AddArticleBarcodeFromOrderAttributes",
3 "props": {
4 "attributeNames": ["barcode"]
5 }
6}1mutation CreateOrder ($retailerId:ID!,
2$productCatalogueRef:String!,
3$productRef:String!,
4$customerId:ID!,
5$ccLocRef:String!) {
6 createOrder(input: {
7 ref: "CC_{{$randomInt}}"
8 retailer: { id:$retailerId }
9 type: "CC"
10 customer: { id:$customerId }
11 totalPrice:80.00
12 attributes:{
13 name:"barcode"
14 value: "B1234"
15 type: "STRING"
16 }
17 items: [{
18 ref: $productRef
19 productRef: $productRef
20 productCatalogueRef:$productCatalogueRef
21 price: 80.00
22 paidPrice:80.00
23 totalPrice:80.00
24 taxPrice:8.00
25 totalTaxPrice: 8.00
26 quantity:1
27 currency:"AUD"
28 }],
29 fulfilmentChoice: {
30 currency: "AUD"
31 deliveryType: "STANDARD"
32 fulfilmentPrice:5.00
33 fulfilmentTaxPrice:0.99
34 fulfilmentType: "CC_PFS"
35 pickupLocationRef: $ccLocRef
36 }
37 }) {
38 id
39 }
40}