{"_id":"@a15-ghm/gh-cart","_rev":"1-4ee87fadf8bf162cb0f669fae3738d49","name":"@a15-ghm/gh-cart","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@a15-ghm/gh-cart","version":"1.0.0","peerDependencies":{"@angular/common":"^16.2.12","@angular/core":"^16.2.12","@ngrx/store":"^16.3.0","ngrx-store-localstorage":"^16.0.0","@a15-ghm/gh-utils":"^4.0.0","@a15-ghm/gh-models":"^2.0.0","deepmerge-ts":"^5.1.0"},"dependencies":{"tslib":"^2.3.0"},"sideEffects":false,"module":"fesm2022/a15-ghm-gh-cart.mjs","typings":"index.d.ts","exports":{"./package.json":{"default":"./package.json"},".":{"types":"./index.d.ts","esm2022":"./esm2022/a15-ghm-gh-cart.mjs","esm":"./esm2022/a15-ghm-gh-cart.mjs","default":"./fesm2022/a15-ghm-gh-cart.mjs"}},"_id":"@a15-ghm/gh-cart@1.0.0","gitHead":"649699227d34239ff0024497dd8f0024015a2409","description":"This library for interacting with app state. Contains:","_nodeVersion":"20.9.0","_npmVersion":"10.1.0","dist":{"integrity":"sha512-yxkzBKjtWTzlLOjTOOXVFEZr6q0b4Wbb1yRkq/XNk8ryl6lMv3sS2i2ybZ4yMIhYJMHLXKD/5Mjv5EHcav4+2w==","shasum":"487d231f8973cc9d993eafe473aeea3b7395c3a0","tarball":"https://registry.npmjs.org/@a15-ghm/gh-cart/-/gh-cart-1.0.0.tgz","fileCount":48,"unpackedSize":155626,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD8cT6BctIaIlzJq6+ZRghePm5y+hZJYKx4pYAbETrovAIgCwu98ndAF2mPmCMR+CHf1An8yvqywFhn2M5h1amTKLQ="}]},"_npmUser":{"name":"devops-ghm-npm","email":"dev@goldenhippo.com"},"directories":{},"maintainers":[{"name":"devops-ghm-npm","email":"dev@goldenhippo.com"},{"name":"danni.liu","email":"danni.liu@goldenhippo.com"},{"name":"s.bely","email":"s.bely@itransition.com"},{"name":"kiskina_victoria","email":"v.kiskina@itransition.com"},{"name":"sergey.kuzovlev","email":"s.kuzovlev@itransition.com"},{"name":"s.bozhik","email":"s.bozhik@itransition.com"},{"name":"brian.park","email":"brian@goldenhippo.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/gh-cart_1.0.0_1701265859059_0.5137262902671094"},"_hasShrinkwrap":false}},"time":{"created":"2023-11-29T13:50:58.985Z","1.0.0":"2023-11-29T13:50:59.253Z","modified":"2024-03-05T12:11:35.191Z"},"maintainers":[{"email":"dev@goldenhippo.com","name":"devops-ghm-npm"},{"email":"danni.liu@goldenhippo.com","name":"danni.liu"},{"email":"s.bely@itransition.com","name":"s.bely"},{"email":"v.kiskina@itransition.com","name":"kiskina_victoria"},{"email":"s.kuzovlev@itransition.com","name":"sergey.kuzovlev"},{"email":"brian@goldenhippo.com","name":"brian.park"}],"description":"This library for interacting with app state. Contains:","readme":"# GhCart\n\nThis library for interacting with app state.\nContains:\n\n1. cart\n\n## To use the `gh-cart` library in your Angular project, follow these steps:\n\n### Installation\n\nInstall the `gh-cart` library by running the following command\n`npm install --save @a15-ghm/gh-cart`\n\n### Importing\n\n```ts\nimport { StoreModule } from '@ngrx/store';\nimport { GhCartModule } from '@a15-ghm/gh-cart';\n\n@NgModule({\n  declarations: [AppComponent],\n  imports: [BrowserModule, AppRoutingModule, StoreModule.forRoot({}), GhCartModule],\n  providers: [],\n  bootstrap: [AppComponent],\n})\n```\n\n### Pass env variables to the a15-ghm/gh-utils library. This is necessary to add a products\n\n```ts\nimport Environment from '@a15-ghm/gh-utils/environment';\nimport { environment } from '../environments/environment';\n\n@Component({\n  selector: 'app-root',\n  templateUrl: './app.component.html',\n  styleUrls: ['./app.component.scss'],\n})\nexport class AppComponent implements OnInit {\n  public ngOnInit() {\n    Environment.setEnvVariables(environment);\n  }\n}\n```\n\n## Using\n\n### Use getCart method to get cart state\n\n```ts\nimport { GhCartService } from '@a15-ghm/gh-cart';\n\n@Component({\n  selector: 'app-root',\n  templateUrl: './app.component.html',\n  styleUrls: ['./app.component.scss'],\n})\nexport class AppComponent implements OnInit {\n  private cart;\n\n  constructor(private ghCartService: GhCartService) {}\n  //or\n  private ghCartService: GhCartService = inject(GhCartService);\n\n  public ngOnInit() {\n    this.ghCartService.getCart().subscribe((cart) => {\n      this.cart = cart;\n    });\n  }\n}\n```\n\n### Use addUrlProducts method to add products\n\n#### Note that you need to pass a method that shows an error to the user when adding a product, and parameters for this method if needed\n\n```ts\n@Component({\n  selector: 'page-cart',\n  templateUrl: './cart.html',\n  styleUrls: ['./cart.scss'],\n})\nexport class CartPageComponent {\n  constructor(private ghCartService: GhCartService) {}\n  //or\n  private ghCartService: GhCartService = inject(GhCartService);\n\n  ngOnInit(): void {\n    this.ghCartService.addUrlProducts(\n      this.toastService.pop.bind(this.toastService, 'something went wrong', SnackbarType.error, 5, SnackbarPosition.topCenter)\n    );\n  }\n}\n```\n\n### Use removeProduct method to remove product\n\n```ts\n@Component({\n  selector: 'page-cart',\n  templateUrl: './cart.html',\n  styleUrls: ['./cart.scss'],\n})\nexport class CartPageComponent {\n  constructor(private ghCartService: GhCartService) {}\n  //or\n  private ghCartService: GhCartService = inject(GhCartService);\n\n  removeProduct(productId: string): void {\n    this.ghCartService.removeProduct(productId);\n  }\n}\n```\n\n### Use incrementProductCount method to increment product\n\n```ts\n@Component({\n  selector: 'page-cart',\n  templateUrl: './cart.html',\n  styleUrls: ['./cart.scss'],\n})\nexport class CartPageComponent {\n  constructor(private ghCartService: GhCartService) {}\n  //or\n  private ghCartService: GhCartService = inject(GhCartService);\n\n  incrementProductCount(sfid: string): void {\n    this.ghCartService.incrementProductCount(sfid);\n  }\n}\n```\n\n### Use decrementProductCount method to decrement product\n\n```ts\n@Component({\n  selector: 'page-cart',\n  templateUrl: './cart.html',\n  styleUrls: ['./cart.scss'],\n})\nexport class CartPageComponent {\n  constructor(private ghCartService: GhCartService) {}\n  //or\n  private ghCartService: GhCartService = inject(GhCartService);\n\n  decrementProductCount(sfid: string): void {\n    this.ghCartService.decrementProductCount(sfid);\n  }\n}\n```\n\n### Use getCartProductsCount method to get products count\n\n```ts\n@Component({\n  selector: 'page-cart',\n  templateUrl: './cart.html',\n  styleUrls: ['./cart.scss'],\n})\nexport class CartPageComponent {\n  private cartProductsCount;\n\n  constructor(private ghCartService: GhCartService) {}\n  //or\n  private ghCartService: GhCartService = inject(GhCartService);\n\n  getCartProductsCount(): void {\n    this.ghCartService.getCartProductsCount().subscribe((cartProductsCount) => {\n      this.cartProductsCount = cartProductsCount;\n    });\n  }\n}\n```\n\n### Use getCartSubtotalBeforeDiscount method to get cart subtotal before discount\n\n```ts\n@Component({\n  selector: 'page-cart',\n  templateUrl: './cart.html',\n  styleUrls: ['./cart.scss'],\n})\nexport class CartPageComponent {\n  private cartSubtotalBeforeDiscount;\n\n  constructor(private ghCartService: GhCartService) {}\n  //or\n  private ghCartService: GhCartService = inject(GhCartService);\n\n  getCartSubtotalBeforeDiscount(): void {\n    this.ghCartService.getCartSubtotalBeforeDiscount().subscribe((cartSubtotalBeforeDiscount) => {\n      this.cartSubtotalBeforeDiscount = cartSubtotalBeforeDiscount;\n    });\n  }\n}\n```\n\n### Use getCartSubtotal method to get cart subtotal\n\n```ts\n@Component({\n  selector: 'page-cart',\n  templateUrl: './cart.html',\n  styleUrls: ['./cart.scss'],\n})\nexport class CartPageComponent {\n  private cartSubtotal;\n\n  constructor(private ghCartService: GhCartService) {}\n  //or\n  private ghCartService: GhCartService = inject(GhCartService);\n\n  getCartSubtotal(): void {\n    this.ghCartService.getCartSubtotal().subscribe((cartSubtotal) => {\n      this.cartSubtotal = cartSubtotal;\n    });\n  }\n}\n```\n\n### Use getCartTotalAmount method to get cart total amount\n\n```ts\n@Component({\n  selector: 'page-cart',\n  templateUrl: './cart.html',\n  styleUrls: ['./cart.scss'],\n})\nexport class CartPageComponent {\n  private cartTotalAmount;\n\n  constructor(private ghCartService: GhCartService) {}\n  //or\n  private ghCartService: GhCartService = inject(GhCartService);\n\n  getCartTotalAmount(): void {\n    this.ghCartService.getCartTotalAmount().subscribe((cartTotalAmount) => {\n      this.cartTotalAmount = cartTotalAmount;\n    });\n  }\n}\n```\n\n### Use clearCart method to remove all products and variants\n\n```ts\n@Component({\n  selector: 'page-cart',\n  templateUrl: './cart.html',\n  styleUrls: ['./cart.scss'],\n})\nexport class CartPageComponent {\n  constructor(private ghCartService: GhCartService) {}\n  //or\n  private ghCartService: GhCartService = inject(GhCartService);\n\n  clearCart(): void {\n    this.ghCartService.clearCart();\n  }\n}\n```\n\n### Use getCartProducts method to get cart products and variants\n\n```ts\n@Component({\n  selector: 'page-cart',\n  templateUrl: './cart.html',\n  styleUrls: ['./cart.scss'],\n})\nexport class CartPageComponent {\n  private productsAndVariants;\n\n  constructor(private ghCartService: GhCartService) {}\n  //or\n  private ghCartService: GhCartService = inject(GhCartService);\n\n  getCartProducts(): void {\n    this.ghCartService.getCartProducts().subscribe((productsAndVariants) => {\n      this.productsAndVariants = productsAndVariants;\n    });\n  }\n}\n```\n\n### Use getCartProductIds method to get cart product IDs\n\n```ts\n@Component({\n  selector: 'page-cart',\n  templateUrl: './cart.html',\n  styleUrls: ['./cart.scss'],\n})\nexport class CartPageComponent {\n  private cartProductIds;\n\n  constructor(private ghCartService: GhCartService) {}\n  //or\n  private ghCartService: GhCartService = inject(GhCartService);\n\n  getCartProductIds(): void {\n    this.ghCartService.getCartProductIds().subscribe((cartProductIds) => {\n      this.cartProductIds = cartProductIds;\n    });\n  }\n}\n```\n","readmeFilename":"README.md"}