Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@itleadopencommerce/api-plugin-delivery-inpost

Package Overview
Dependencies
Maintainers
5
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@itleadopencommerce/api-plugin-delivery-inpost - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

2

package.json

@@ -5,3 +5,3 @@ {

"label": "Inpost Delivery Plugin",
"version": "0.0.1",
"version": "0.0.2",
"main": "index.js",

@@ -8,0 +8,0 @@ "type": "module",

@@ -49,29 +49,8 @@ import bodyParser from "body-parser";

// Dynamic update delivery rate
// Dynamic update selectedMethod delivery rate
appEvents.on("afterCartUpdate", async ({ cart }) => {
const { _id: cartId } = cart;
const { shipmentQuotes } = cart.shipping[0];
const selectedMethod = cart.shipping[0].shipmentMethod;
const [calculateDeliveryPrice] = context.getFunctionsOfType("calculateDeliveryPrice");
const prices = {
inpost_locker_standard: 0,
inpost_courier_standard: 0
};
if (shipmentQuotes) {
for (const shipmentQuote of shipmentQuotes) {
switch (shipmentQuote.method.name) {
case "inpost_locker_standard":
case "inpost_courier_standard":
prices[shipmentQuote.method.name] = await calculateDeliveryPrice(context, cart, "inpost_locker_standard"); // shipmentQuote.method.name
Cart.findOneAndUpdate(
{ "_id": cartId, "shipping.0.shipmentQuotes.method.name": shipmentQuote.method.name },
{ $set: { "shipping.0.shipmentQuotes.$.rate": prices[shipmentQuote.method.name] } }
);
}
}
}
if (selectedMethod) {

@@ -83,3 +62,3 @@ switch (selectedMethod.name) {

{ _id: cartId },
{ $set: { "shipping.0.shipmentMethod.rate": prices[selectedMethod.name] } }
{ $set: { "shipping.0.shipmentMethod.rate": await calculateDeliveryPrice(context, cart, "inpost_locker_standard") } }
);

@@ -86,0 +65,0 @@ }

@@ -7,15 +7,19 @@ import sendRequest from "./sendRequest.js";

const shipments = await createShipmentsObjects(context, cart, deliveryMethod);
try {
const shipments = await createShipmentsObjects(context, cart, deliveryMethod);
const action = "shipmentsCalculate";
const response = await sendRequest(context, shopId, action, shipments);
const action = "shipmentsCalculate";
const response = await sendRequest(context, shopId, action, shipments);
// if (response.status !== 200) return null;
// if (response.status !== 200) return null;
let deliveryPrice = 0;
for (const price of await response.json()) {
deliveryPrice += Number(price.calculated_charge_amount);
let deliveryPrice = 0;
for (const price of await response.json()) {
deliveryPrice += Number(price.calculated_charge_amount);
}
return deliveryPrice;
} catch (err) {
console.log(err.message);
return 0;
}
return deliveryPrice;
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc