coopdevs / lazona_connector

1 stars 0 forks source link

Update delivery when woocommerce order updates #98

Open daniquilez opened 3 years ago

daniquilez commented 3 years ago
numeropi commented 3 years ago

Trying the Order update webhook I realized that it is only triggered when we change details of the order like client's shipping or billing address, but not the vendor's internal address that it is outside the Order's edit reach.

I discovered that when editing Woocomerce's order, there is an option "Acciones del pedido" that allows to force a new "Enviar aviso de nuevo pedido" and that could be useful in case that we change the vendor's details too and that could trigger our new order existant webhook and we could compare order_id if already existing in our Shipping persistent model.

image

Output of the payload raw received in the order update webhook...

{ "id": 6314, #this is the ID of the order "parent_id": 0, "status": "pending", "currency": "EUR", "version": "5.0.0", "prices_include_tax": false, "date_created": "2021-07-08T18:20:32", "date_modified": "2021-07-16T17:22:19", "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "0.00", "shipping_tax": "0.00", "cart_tax": "0.00", "total": "6.00", "total_tax": "0.00", "customer_id": 1, "order_key": "wc_order_YHORUPQ0pc6Dc", "billing": { "first_name": "Sergi", "last_name": "Alonso", "company": "Coopdevs", "address_1": "YYYYYY", "address_2": "", "city": "Barcelona", "state": "B", "postcode": "11111", "country": "ES", "email": "sxxxxxx@coopdevs.org", "phone": "xxxxxx" }, "shipping": { "first_name": "Sergi", "last_name": "xxxx", "company": "Coopdevs", "address_1": "XXXXX", "address_2": "", "city": "Barcelona", "state": "B", "postcode": "33333", "country": "ES" }, "payment_method": "", "payment_method_title": "", "transaction_id": "", "customer_ip_address": "", "customer_user_agent": "", "created_via": "admin", "customer_note": "", "date_completed": null, "date_paid": null, "cart_hash": "", "number": "6314", "meta_data": [ { "id": 23108, "key": "_wcfmmp_order_processed", "value": "yes" }, { "id": 23110, "key": "_wp_page_template", "value": "default" }, { "id": 23143, "key": "rs_page_bg_color", "value": "" } ], "line_items": [ { "id": 156, "name": "Xampú sòlid cabells grassos", "product_id": 5263, "variation_id": 0, "quantity": 1, "tax_class": "", "subtotal": "6.00", "subtotal_tax": "0.00", "total": "6.00", "total_tax": "0.00", "taxes": [], "meta_data": [ { "id": 1513, "key": "_vendor_id", "value": "5", "display_key": "Tienda", "display_value": "A granel" }, { "id": 1514, "key": "_wcfmmp_order_item_processed", "value": "82", "display_key": "ID de pedido", "display_value": "82" } ], "sku": "", "price": 6, "parent_name": null } ], "tax_lines": [], "shipping_lines": [], "fee_lines": [], "coupon_lines": [], "refunds": [], "date_created_gmt": "2021-07-08T16:20:32", "date_modified_gmt": "2021-07-16T15:22:19", "date_completed_gmt": null, "date_paid_gmt": null, "currency_symbol": "€", "payment_url": "http://staging.lazona.coop/pagament/order-pay/6314/?pay_for_order=true&key=wc_order_YHORUPQ0pc6Dc", "_links": { "self": [ { "href": "http://staging.lazona.coop/wp-json/wc/v3/orders/6314" } ], "collection": [ { "href": "http://staging.lazona.coop/wp-json/wc/v3/orders" } ], "customer": [ { "href": "http://staging.lazona.coop/wp-json/wc/v3/customers/1" } ] } }

numeropi commented 3 years ago

Added "retry delivery" button in the view/edit admin form of the Delivery model. Non superusers shoul just have permission to view the model, (to not be able to change the order's or vendor's id ) and also they are able to push the button to trigger the retry sending the delivery to Koiki's.

image