@haus-tech/package-size-plugin 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,13 +2,14 @@
2
2
 
3
3
  1. Copy this directory and rename to `vendure-plugin-YOUR-PLUGIN-NAME`
4
4
  2. Update the `name` and `description` field in `package.json`
5
- 4. Update this Readme: What does the plugin do? How can someone use your plugin in their project?
6
- 5. Run `yarn` to install the dependencies
7
- 6. Run `yarn start` to start the server
5
+ 3. Update this Readme: What does the plugin do? How can someone use your plugin in their project?
6
+ 4. Run `yarn` to install the dependencies
7
+ 5. Run `yarn start` to start the server
8
8
 
9
9
  The admin is now available at `http://localhost:3050/admin`. Login with _superadmin/superadmin_
10
10
 
11
11
  The shop GraphQL `http://localhost:3050/shop-api`. Here you can test your custom GraphQL query:
12
+
12
13
  ```graphql
13
14
  {
14
15
  exampleQuery
@@ -34,3 +35,25 @@ That's it!
34
35
 
35
36
  1. Check out [the docs](https://www.vendure.io/docs/plugins/) to see the possibilities of a plugin
36
37
  2. Check out [GraphQL codegen](https://the-guild.dev/graphql/codegen) to generate Typescript types for your custom GraphQL types
38
+
39
+ ## Index Packagesize in ElasticsearchPlugin
40
+ - Add following to elasticSearchConfig
41
+
42
+ In indexMappingProperties:
43
+
44
+ ```
45
+ 'variant-packageSize': {
46
+ type: 'integer',
47
+ },
48
+ ```
49
+
50
+ In customProductVariantMappings:
51
+
52
+ ```
53
+ packageSize: {
54
+ graphQlType: 'Int!',
55
+ valueFn: async (productVariant: ProductVariant ) => {
56
+ return productVariant.customFields.packageSizeInternal
57
+ },
58
+ },
59
+ ```
@@ -8,5 +8,6 @@ const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
8
  exports.shopApiExtensions = (0, graphql_tag_1.default) `
9
9
  extend type ProductVariant {
10
10
  packageSize: Int
11
+ packageSizeUnit: String
11
12
  }
12
13
  `;
@@ -2,4 +2,5 @@ import { RequestContext, ProductVariant } from '@vendure/core';
2
2
  export declare class ProductVariantEntityResolver {
3
3
  constructor();
4
4
  packageSize(ctx: RequestContext, variant: ProductVariant): number;
5
+ packageSizeUnit(ctx: RequestContext, variant: ProductVariant): string;
5
6
  }
@@ -20,7 +20,11 @@ let ProductVariantEntityResolver = class ProductVariantEntityResolver {
20
20
  packageSize(ctx, variant) {
21
21
  return variant.customFields.packageSizeInternal || 1;
22
22
  }
23
+ packageSizeUnit(ctx, variant) {
24
+ return variant.customFields.packageSizeUnitInternal || 'st';
25
+ }
23
26
  };
27
+ exports.ProductVariantEntityResolver = ProductVariantEntityResolver;
24
28
  __decorate([
25
29
  (0, graphql_1.ResolveField)(),
26
30
  __param(0, (0, core_1.Ctx)()),
@@ -29,8 +33,15 @@ __decorate([
29
33
  __metadata("design:paramtypes", [core_1.RequestContext, core_1.ProductVariant]),
30
34
  __metadata("design:returntype", void 0)
31
35
  ], ProductVariantEntityResolver.prototype, "packageSize", null);
32
- ProductVariantEntityResolver = __decorate([
36
+ __decorate([
37
+ (0, graphql_1.ResolveField)(),
38
+ __param(0, (0, core_1.Ctx)()),
39
+ __param(1, (0, graphql_1.Parent)()),
40
+ __metadata("design:type", Function),
41
+ __metadata("design:paramtypes", [core_1.RequestContext, core_1.ProductVariant]),
42
+ __metadata("design:returntype", void 0)
43
+ ], ProductVariantEntityResolver.prototype, "packageSizeUnit", null);
44
+ exports.ProductVariantEntityResolver = ProductVariantEntityResolver = __decorate([
33
45
  (0, graphql_1.Resolver)('ProductVariant'),
34
46
  __metadata("design:paramtypes", [])
35
47
  ], ProductVariantEntityResolver);
36
- exports.ProductVariantEntityResolver = ProductVariantEntityResolver;
@@ -1,9 +1,22 @@
1
+ import { LanguageCode } from '@vendure/core';
2
+ export interface PackageSizeUnit {
3
+ value: string;
4
+ label: {
5
+ languageCode: LanguageCode;
6
+ value: string;
7
+ }[];
8
+ }
9
+ export interface PackageSizePluginConfig {
10
+ defaultUnit?: string;
11
+ }
1
12
  declare module '@vendure/core' {
2
13
  interface CustomProductVariantFields {
3
14
  packageSizeInternal: number;
15
+ packageSizeUnitInternal: string;
4
16
  }
5
17
  interface ProductVariant {
6
18
  packageSize: number;
19
+ packageSizeUnit: string;
7
20
  }
8
21
  }
9
22
  export declare class PackageSizePlugin {
@@ -12,7 +12,8 @@ const api_extensions_1 = require("./api/api-extensions");
12
12
  const package_size_resolver_1 = require("./api/package-size.resolver");
13
13
  let PackageSizePlugin = class PackageSizePlugin {
14
14
  };
15
- PackageSizePlugin = __decorate([
15
+ exports.PackageSizePlugin = PackageSizePlugin;
16
+ exports.PackageSizePlugin = PackageSizePlugin = __decorate([
16
17
  (0, core_1.VendurePlugin)({
17
18
  imports: [core_1.PluginCommonModule],
18
19
  shopApiExtensions: {
@@ -20,6 +21,8 @@ PackageSizePlugin = __decorate([
20
21
  schema: api_extensions_1.shopApiExtensions,
21
22
  },
22
23
  configuration: (config) => {
24
+ const pluginConfig = config.packageSize || {};
25
+ const defaultUnit = pluginConfig.defaultUnit || 'st';
23
26
  config.customFields.ProductVariant.push({
24
27
  name: 'packageSizeInternal',
25
28
  type: 'int',
@@ -29,10 +32,21 @@ PackageSizePlugin = __decorate([
29
32
  { languageCode: core_1.LanguageCode.en, value: 'Package Size' },
30
33
  { languageCode: core_1.LanguageCode.sv, value: 'Förpackningsstorlek' },
31
34
  ],
35
+ }, {
36
+ name: 'packageSizeUnitInternal',
37
+ type: 'string',
38
+ defaultValue: defaultUnit,
39
+ ui: {
40
+ component: 'text-form-input',
41
+ },
42
+ public: false,
43
+ label: [
44
+ { languageCode: core_1.LanguageCode.en, value: 'Package Size Unit' },
45
+ { languageCode: core_1.LanguageCode.sv, value: 'Förpackningsenhet' },
46
+ ],
32
47
  });
33
48
  return config;
34
49
  },
35
50
  compatibility: '^3.0.0',
36
51
  })
37
52
  ], PackageSizePlugin);
38
- exports.PackageSizePlugin = PackageSizePlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haus-tech/package-size-plugin",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Package size plugin for Vendure",
5
5
  "author": "Haus Tech",
6
6
  "repository": {