From 1075382575298ad03d3963870b45e8ed4caa94a0 Mon Sep 17 00:00:00 2001 From: OlegApanovich Date: Thu, 19 Nov 2020 00:31:51 +0200 Subject: [PATCH 001/249] Fix filter woocommerce_shipping_rate_cost backwards compatible with cart taxes #28008 --- includes/class-wc-tax.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/includes/class-wc-tax.php b/includes/class-wc-tax.php index f80a7d8422d..b8fe9f72f1e 100644 --- a/includes/class-wc-tax.php +++ b/includes/class-wc-tax.php @@ -82,7 +82,13 @@ class WC_Tax { * @return array */ public static function calc_shipping_tax( $price, $rates ) { + // Backwards compatible from WC_Shipping_Rate::get_cost(). + if ( has_filter( 'woocommerce_shipping_rate_cost' ) ) { + $rate = new WC_Shipping_Rate(); + $price = $rate->get_cost(); + } $taxes = self::calc_exclusive_tax( $price, $rates ); + return apply_filters( 'woocommerce_calc_shipping_tax', $taxes, $price, $rates ); } From 142fafc60eb0c266357c0c8772061ce942e8e77b Mon Sep 17 00:00:00 2001 From: jjchrisdiehl Date: Tue, 26 Jan 2021 09:42:05 -0500 Subject: [PATCH 002/249] Adding Venezuelan states --- i18n/states.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/i18n/states.php b/i18n/states.php index cda1e51e4aa..25fdd505ba8 100644 --- a/i18n/states.php +++ b/i18n/states.php @@ -1735,6 +1735,33 @@ return array( 'AE' => __( 'Armed Forces (AE)', 'woocommerce' ), 'AP' => __( 'Armed Forces (AP)', 'woocommerce' ), ), + 'VE' => array( // Venezuela States. Ref: https://en.wikipedia.org/wiki/ISO_3166-2:VE + 'W' => __( 'Dependencias Federales', 'woocommerce' ), + 'A' => __( 'Distrito Capital', 'woocommerce' ), + 'Z' => __( 'Amazonas', 'woocommerce' ), + 'B' => __( 'Anzoátegui', 'woocommerce' ), + 'C' => __( 'Apure', 'woocommerce' ), + 'D' => __( 'Aragua', 'woocommerce' ), + 'E' => __( 'Barinas', 'woocommerce' ), + 'F' => __( 'Bolívar', 'woocommerce' ), + 'G' => __( 'Carabobo', 'woocommerce' ), + 'H' => __( 'Cojedes', 'woocommerce' ), + 'Y' => __( 'Delta Amacuro', 'woocommerce' ), + 'I' => __( 'Falcón', 'woocommerce' ), + 'J' => __( 'Guárico', 'woocommerce' ), + 'K' => __( 'Lara', 'woocommerce' ), + 'L' => __( 'Mérida', 'woocommerce' ), + 'M' => __( 'Miranda', 'woocommerce' ), + 'N' => __( 'Monagas', 'woocommerce' ), + 'O' => __( 'Nueva Esparta', 'woocommerce' ), + 'P' => __( 'Portuguesa', 'woocommerce' ), + 'R' => __( 'Sucre', 'woocommerce' ), + 'S' => __( 'Táchira', 'woocommerce' ), + 'T' => __( 'Trujillo', 'woocommerce' ), + 'X' => __( 'La Guaira', 'woocommerce' ), + 'U' => __( 'Yaracuy', 'woocommerce' ), + 'V' => __( 'Zulia', 'woocommerce' ), + ), 'VN' => array(), 'YT' => array(), 'ZA' => array( // South African states. From 7a892f61d28f1c10ad198f3626bc12e5b0211958 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Wed, 3 Mar 2021 19:52:29 -0400 Subject: [PATCH 003/249] update shared objects among models - add optional defaultKey, defaultValue to meta data - move REST _links object to model shared - add _links collection to coupons --- tests/e2e/api/src/models/coupons/coupon.ts | 11 +++ .../src/models/products/abstract/common.ts | 8 +-- .../api/src/models/products/abstract/data.ts | 8 +-- .../api/src/models/products/shared/classes.ts | 56 --------------- .../e2e/api/src/models/products/variation.ts | 8 +-- tests/e2e/api/src/models/shared-types.ts | 70 +++++++++++++++++++ .../repositories/rest/coupons/transformer.ts | 1 + tests/e2e/api/src/repositories/rest/shared.ts | 7 ++ 8 files changed, 101 insertions(+), 68 deletions(-) diff --git a/tests/e2e/api/src/models/coupons/coupon.ts b/tests/e2e/api/src/models/coupons/coupon.ts index a0ee904de29..20e3f42ee9b 100644 --- a/tests/e2e/api/src/models/coupons/coupon.ts +++ b/tests/e2e/api/src/models/coupons/coupon.ts @@ -12,6 +12,7 @@ import { import { CouponUpdateParams, } from './shared'; +import { ObjectLinks } from '../shared-types'; /** * The parameters embedded in this generic can be used in the ModelRepository in order to give @@ -222,6 +223,16 @@ export class Coupon extends Model { */ public readonly usedBy: Array = []; + /** + * The coupon's links. + * + * @type {ReadonlyArray.} + */ + public readonly links: ObjectLinks = { + collection: [ { href: '' } ], + self: [ { href: '' } ], + }; + /** * Creates a new coupon instance with the given properties * diff --git a/tests/e2e/api/src/models/products/abstract/common.ts b/tests/e2e/api/src/models/products/abstract/common.ts index 88601fa6ad0..4f9833f8eab 100644 --- a/tests/e2e/api/src/models/products/abstract/common.ts +++ b/tests/e2e/api/src/models/products/abstract/common.ts @@ -3,9 +3,9 @@ import { ModelID } from '../../model'; import { CatalogVisibility, ProductTerm, - ProductLinks, ProductAttribute, } from '../shared'; +import { ObjectLinks } from '../../shared-types'; /** * The common parameters that all products can use in search. @@ -137,11 +137,11 @@ export abstract class AbstractProduct extends AbstractProductData { public readonly attributes: readonly ProductAttribute[] = []; /** - * The products links. + * The product's links. * - * @type {ReadonlyArray.} + * @type {ReadonlyArray.} */ - public readonly links: ProductLinks = { + public readonly links: ObjectLinks = { collection: [ { href: '' } ], self: [ { href: '' } ], }; diff --git a/tests/e2e/api/src/models/products/abstract/data.ts b/tests/e2e/api/src/models/products/abstract/data.ts index 0d1b83cb37e..e76c1c7d9d8 100644 --- a/tests/e2e/api/src/models/products/abstract/data.ts +++ b/tests/e2e/api/src/models/products/abstract/data.ts @@ -1,6 +1,6 @@ import { Model } from '../../model'; -import { MetaData, PostStatus } from '../../shared-types'; -import { ProductImage, ProductLinks } from '../shared'; +import { MetaData, PostStatus, ObjectLinks } from '../../shared-types'; +import { ProductImage } from '../shared'; /** * Base product data. @@ -93,9 +93,9 @@ export abstract class AbstractProductData extends Model { /** * The product data links. * - * @type {ReadonlyArray.} + * @type {ReadonlyArray.} */ - public readonly links: ProductLinks = { + public readonly links: ObjectLinks = { collection: [ { href: '' } ], self: [ { href: '' } ], }; diff --git a/tests/e2e/api/src/models/products/shared/classes.ts b/tests/e2e/api/src/models/products/shared/classes.ts index 7343c594352..c08e0a20b70 100644 --- a/tests/e2e/api/src/models/products/shared/classes.ts +++ b/tests/e2e/api/src/models/products/shared/classes.ts @@ -208,59 +208,3 @@ export class ProductImage { Object.assign( this, properties ); } } - -/** - * A product link item. - */ -class ProductLinkItem { - /** - * The options which are available for the attribute. - * - * @type {ReadonlyArray.} - */ - public readonly href: string = ''; - - /** - * Creates a new product link item. - * - * @param {Partial.} properties The properties to set. - */ - public constructor( properties?: Partial< ProductLinkItem > ) { - Object.assign( this, properties ); - } -} - -/** - * A product's links. - */ -export class ProductLinks { - /** - * The collection containing the product. - * - * @type {ReadonlyArray.} - */ - public readonly collection: readonly ProductLinkItem[] = []; - - /** - * Self referential link to the product. - * - * @type {ReadonlyArray.} - */ - public readonly self: readonly ProductLinkItem[] = []; - - /** - * The link to the parent. - * - * @type {ReadonlyArray.} - */ - public readonly up?: readonly ProductLinkItem[] = []; - - /** - * Creates a new product link list. - * - * @param {Partial.} properties The properties to set. - */ - public constructor( properties?: Partial< ProductLinks > ) { - Object.assign( this, properties ); - } -} diff --git a/tests/e2e/api/src/models/products/variation.ts b/tests/e2e/api/src/models/products/variation.ts index 78e8580c2fa..beb1bad8071 100644 --- a/tests/e2e/api/src/models/products/variation.ts +++ b/tests/e2e/api/src/models/products/variation.ts @@ -15,13 +15,13 @@ import { ProductPriceUpdateParams, ProductSalesTaxUpdateParams, ProductShippingUpdateParams, - ProductLinks, Taxability, ProductDownload, StockStatus, BackorderStatus, ProductDefaultAttribute, } from './shared'; +import { ObjectLinks } from '../shared-types'; import { CreatesChildModels, DeletesChildModels, @@ -149,11 +149,11 @@ export class ProductVariation extends AbstractProductData implements public readonly shippingClassId: number = 0; /** - * The variation links. + * The variation's links. * - * @type {ReadonlyArray.} + * @type {ReadonlyArray.} */ - public readonly links: ProductLinks = { + public readonly links: ObjectLinks = { collection: [ { href: '' } ], self: [ { href: '' } ], up: [ { href: '' } ], diff --git a/tests/e2e/api/src/models/shared-types.ts b/tests/e2e/api/src/models/shared-types.ts index 5f64fff0b72..d041f3c48c8 100644 --- a/tests/e2e/api/src/models/shared-types.ts +++ b/tests/e2e/api/src/models/shared-types.ts @@ -35,6 +35,20 @@ export class MetaData extends Model { */ public readonly value: any = ''; + /** + * The key of the metadata. + * + * @type {string} + */ + public readonly displayKey?: string = ''; + + /** + * The value of the metadata. + * + * @type {*} + */ + public readonly displayValue?: string = ''; + /** * Creates a new metadata. * @@ -45,3 +59,59 @@ export class MetaData extends Model { Object.assign( this, properties ); } } + +/** + * An object link item. + */ +class LinkItem { + /** + * The href of the link. + * + * @type {ReadonlyArray.} + */ + public readonly href: string = ''; + + /** + * Creates a new product link item. + * + * @param {Partial.} properties The properties to set. + */ + public constructor( properties?: Partial< LinkItem > ) { + Object.assign( this, properties ); + } +} + +/** + * An object's links. + */ +export class ObjectLinks { + /** + * The collection containing the object. + * + * @type {ReadonlyArray.} + */ + public readonly collection: readonly LinkItem[] = []; + + /** + * Self referential link to the object. + * + * @type {ReadonlyArray.} + */ + public readonly self: readonly LinkItem[] = []; + + /** + * The link to the parent object. + * + * @type {ReadonlyArray.} + */ + public readonly up?: readonly LinkItem[] = []; + + /** + * Creates a new product link list. + * + * @param {Partial.} properties The properties to set. + */ + public constructor( properties?: Partial< ObjectLinks > ) { + Object.assign( this, properties ); + } +} diff --git a/tests/e2e/api/src/repositories/rest/coupons/transformer.ts b/tests/e2e/api/src/repositories/rest/coupons/transformer.ts index b3827471242..8e0c7d85eb9 100644 --- a/tests/e2e/api/src/repositories/rest/coupons/transformer.ts +++ b/tests/e2e/api/src/repositories/rest/coupons/transformer.ts @@ -57,6 +57,7 @@ export function createCouponTransformer(): ModelTransformer< Coupon > { maximumAmount: 'maximum_amount', emailRestrictions: 'email_restrictions', usedBy: 'used_by', + links: '_links', }, ), ], diff --git a/tests/e2e/api/src/repositories/rest/shared.ts b/tests/e2e/api/src/repositories/rest/shared.ts index 1d52d73ec3d..3c4e976d177 100644 --- a/tests/e2e/api/src/repositories/rest/shared.ts +++ b/tests/e2e/api/src/repositories/rest/shared.ts @@ -16,6 +16,7 @@ import { CreateChildFn, ModelTransformer, IgnorePropertyTransformation, + KeyChangeTransformation, // @ts-ignore ModelParentID, } from '../../framework'; @@ -34,6 +35,12 @@ export function createMetaDataTransformer(): ModelTransformer< MetaData > { return new ModelTransformer( [ new IgnorePropertyTransformation( [ 'id' ] ), + new KeyChangeTransformation< MetaData >( + { + displayKey: 'display_key', + displayValue: 'display_value', + }, + ), ], ); } From 03c60b988b086b15e23e8760e9c67eb9a65a33b9 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Fri, 5 Mar 2021 10:39:35 -0400 Subject: [PATCH 004/249] add order classes --- tests/e2e/api/src/models/orders/index.ts | 1 + .../api/src/models/orders/shared/classes.ts | 412 ++++++++++++++++++ .../e2e/api/src/models/orders/shared/index.ts | 2 + .../e2e/api/src/models/orders/shared/types.ts | 3 + 4 files changed, 418 insertions(+) create mode 100644 tests/e2e/api/src/models/orders/index.ts create mode 100644 tests/e2e/api/src/models/orders/shared/classes.ts create mode 100644 tests/e2e/api/src/models/orders/shared/index.ts create mode 100644 tests/e2e/api/src/models/orders/shared/types.ts diff --git a/tests/e2e/api/src/models/orders/index.ts b/tests/e2e/api/src/models/orders/index.ts new file mode 100644 index 00000000000..c3da79f741b --- /dev/null +++ b/tests/e2e/api/src/models/orders/index.ts @@ -0,0 +1 @@ +export * from './shared'; diff --git a/tests/e2e/api/src/models/orders/shared/classes.ts b/tests/e2e/api/src/models/orders/shared/classes.ts new file mode 100644 index 00000000000..3852519b94c --- /dev/null +++ b/tests/e2e/api/src/models/orders/shared/classes.ts @@ -0,0 +1,412 @@ +import { MetaData } from '../../shared-types'; +import { Model } from '../../model'; +import { TaxStatus } from './types'; + +/** + * Order item meta. + */ +export class OrderItemMeta extends Model { + /** + * The meta data the order item. + * + * @type {ReadonlyArray.} + */ + public readonly metaData: MetaData[] = []; +} + +/** + * Order line item tax entry. + */ +export class OrderItemTax extends Model { + /** + * The total tax for this tax rate on this item. + * + * @type {string} + */ + public readonly total: string = ''; + + /** + * The subtotal tax for this tax rate on this item. + * + * @type {string} + */ + public readonly subtotal: string = ''; +} + +/** + * An order address. + */ +export class OrderAddress { + /** + * The first name of the person in the address. + * + * @type {string} + */ + public readonly firstName: string = ''; + + /** + * The last name of the person in the address. + * + * @type {string} + */ + public readonly lastName: string = ''; + + /** + * The company name of the person in the address. + * + * @type {string} + */ + public readonly companyName: string = ''; + + /** + * The first address line in the address. + * + * @type {string} + */ + public readonly address1: string = ''; + + /** + * The second address line in the address. + * + * @type {string} + */ + public readonly address2: string = ''; + + /** + * The city in the address. + * + * @type {string} + */ + public readonly city: string = ''; + + /** + * The state in the address. + * + * @type {string} + */ + public readonly state: string = ''; + + /** + * The postal code in the address. + * + * @type {string} + */ + public readonly postCode: string = ''; + + /** + * The country code for the address. + * + * @type {string} + */ + public readonly countryCode: string = ''; + + /** + * The email address of the person in the address. + * + * @type {string} + */ + public readonly email: string = ''; + + /** + * The phone number of the person in the address. + * + * @type {string} + */ + public readonly phone: string = ''; +} + +/** + * Order Line Item + */ +export class OrderLineItem extends OrderItemMeta { + /** + * The name of the product. + * + * @type {string} + */ + public readonly name: string = ''; + + /** + * The ID of the product. + * + * @type {number} + */ + public readonly ProductId: number = -1; + + /** + * The ID of the product variation. + * + * @type {number} + */ + public readonly variationId: number = 0; + + /** + * The quantity of the product. + * + * @type {number} + */ + public readonly quantity: number = -1; + + /** + * The tax class for the product. + * + * @type {string} + */ + public readonly taxClass: string = ''; + + /** + * The subtotal for the product. + * + * @type {string} + */ + public readonly subtotal: string = ''; + + /** + * The subtotal tax for the product. + * + * @type {string} + */ + public readonly subtotalTax: string = ''; + + /** + * The total for the product including adjusments. + * + * @type {string} + */ + public readonly total: string = ''; + + /** + * The total tax for the product including adjusments. + * + * @type {string} + */ + public readonly totalTax: string = ''; + + /** + * The taxes applied to the product. + * + * @type {ReadonlyArray.} + */ + public readonly taxes: OrderItemTax[] = []; + + /** + * The product SKU. + * + * @type {string} + */ + public readonly sku: string = ''; + + /** + * The price of the product. + * + * @type {number} + */ + public readonly price: number = -1; + + /** + * The name of the parent product. + * + * @type {string|null} + */ + public readonly parentName: string | null = null; +} + +/** + * Order Tax Rate + */ +export class OrderTaxRate extends Model { + /** + * The tax rate code. + * + * @type {string} + */ + public readonly rateCode: string = ''; + + /** + * The tax rate id. + * + * @type {number} + */ + public readonly rateId: number = 0; + + /** + * The tax label. + * + * @type {string} + */ + public readonly label: string = ''; + + /** + * Flag indicating whether it's a compound tax rate. + * + * @type {boolean} + */ + public readonly compoundRate: boolean = false; + + /** + * The total tax for this rate code. + * + * @type {string} + */ + public readonly taxTotal: string = ''; + + /** + * The total shipping tax for this rate code. + * + * @type {string} + */ + public readonly shippingTaxTotal: string = ''; + + /** + * The tax rate as a percentage. + * + * @type {number} + */ + public readonly ratePercent: number = 0; +} + +/** + * Order shipping line + */ +export class OrderShippingLine extends OrderItemMeta { + /** + * The shipping method title. + * + * @type {string} + */ + public readonly methodTitle: string = ''; + + /** + * The shipping method id. + * + * @type {string} + */ + public readonly methodId: string = ''; + + /** + * The shipping method instance id. + * + * @type {string} + */ + public readonly instanceId: string = ''; + + /** + * The total shipping amount for this method. + * + * @type {string} + */ + public readonly total: string = ''; + + /** + * The total tax amount for this shipping method. + * + * @type {string} + */ + public readonly totalTax: string = ''; + + /** + * The taxes applied to this shipping method. + * + * @type {ReadonlyArray.} + */ + public readonly taxes: OrderItemTax[] = []; +} + +/** + * Order fee line + */ +export class OrderFeeLine extends OrderItemMeta { + /** + * The name of the fee. + * + * @type {string} + */ + public readonly name: string = ''; + + /** + * The tax class of the fee. + * + * @type {string} + */ + public readonly taxClass: string = ''; + + /** + * The tax status of the fee. + * + * @type {TaxStatus} + */ + public readonly taxStatus: TaxStatus = ''; + + /** + * The total amount for this fee. + * + * @type {string} + */ + public readonly amount: string = ''; + + /** + * The display total amount for this fee. + * + * @type {string} + */ + public readonly total: string = ''; + + /** + * The total tax amount for this fee. + * + * @type {string} + */ + public readonly totalTax: string = ''; + + /** + * The taxes applied to this fee. + * + * @type {ReadonlyArray.} + */ + public readonly taxes: OrderItemTax[] = []; +} + +/** + * Order coupon line + */ +export class OrderCouponLine extends OrderItemMeta { + /** + * The coupon code + * + * @type {string} + */ + public readonly code: string = ''; + + /** + * The discount amount. + * + * @type {string} + */ + public readonly discount: string = ''; + + /** + * The discount tax. + * + * @type {string} + */ + public readonly discountTax: string = ''; +} + +/** + * Order refund line + */ +export class OrderRefundLine extends Model { + /** + * The reason for giving the refund. + * + * @type {string} + */ + public readonly reason: string = ''; + + /** + * The total amount of the refund. + * + * @type {string} + */ + public readonly total: string = ''; +} diff --git a/tests/e2e/api/src/models/orders/shared/index.ts b/tests/e2e/api/src/models/orders/shared/index.ts new file mode 100644 index 00000000000..15eb796c953 --- /dev/null +++ b/tests/e2e/api/src/models/orders/shared/index.ts @@ -0,0 +1,2 @@ +export * from './classes'; +export * from './types'; diff --git a/tests/e2e/api/src/models/orders/shared/types.ts b/tests/e2e/api/src/models/orders/shared/types.ts new file mode 100644 index 00000000000..4e987c99d24 --- /dev/null +++ b/tests/e2e/api/src/models/orders/shared/types.ts @@ -0,0 +1,3 @@ + +//@todo: complete this type +export type TaxStatus = 'taxable' | string; From b05a97e2c069f3dffbc23e576bbd9529eb729343 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Sun, 7 Mar 2021 23:06:48 -0400 Subject: [PATCH 005/249] add order types --- .../e2e/api/src/models/orders/shared/types.ts | 67 ++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/tests/e2e/api/src/models/orders/shared/types.ts b/tests/e2e/api/src/models/orders/shared/types.ts index 4e987c99d24..adeba0128c4 100644 --- a/tests/e2e/api/src/models/orders/shared/types.ts +++ b/tests/e2e/api/src/models/orders/shared/types.ts @@ -1,3 +1,66 @@ +/** + * An order's status. + * + * @typedef OrderStatus + */ +export type OrderStatus = 'pending' | 'processing' | 'complete' | 'on-hold' | 'refunded' + | 'cancelled' | 'failed' | 'trash' | string; -//@todo: complete this type -export type TaxStatus = 'taxable' | string; +/** + * An fee's tax status. + * + * @typedef TaxStatus + */ +export type TaxStatus = 'taxable' | 'none'; + +/** + * Base order properties + */ +export type OrderDataUpdateParams = 'id' | 'parentId' | 'status' | 'currency' | 'version' + | 'pricesIncludeTax' | 'discountTotal' | 'discountTax' | 'shippingTotal' | 'shippingTax' + | 'cartTax' | 'customerId' | 'orderKey' | 'paymentMethod' | 'paymentMethodTitle' + | 'transactionId' | 'customerIpAddress' | 'customerUserAgent' | 'createdVia' | 'datePaid' + | 'customerNote' | 'dateCompleted' | 'cartHash' | 'orderNumber' | 'currencySymbol'; + +/** + * Common total properties + */ +export type OrderTotalUpdateParams = 'total' | 'totalTax'; + +/** + * Order address properties + */ +export type OrderAddressUpdateParams = 'firstName' | 'lastName' | 'companyName' | 'address1' + | 'address2' | 'city' | 'state' | 'postCode' | 'countryCode' | 'email' | 'phone'; + +/** + * Line item properties + */ +export type OrderLineItemUpdateParams = 'name' | 'ProductId' | 'variationId' | 'quantity' + | 'taxClass' | 'subtotal' | 'subtotalTax' | 'sku' | 'price' | 'parentName'; + +/** + * Tax rate properties + */ +export type OrderTaxUpdateParams = 'rateCode' | 'rateId' | 'label' | 'compoundRate' + | 'taxTotal' | 'shippingTaxTotal' | 'ratePercent'; + +/** + * Order shipping properties + */ +export type OrderShippingUpdateParams = 'methodTitle' | 'methodId' | 'instanceId'; + +/** + * Order fee properties + */ +export type OrderFeeUpdateParams = 'name' | 'taxClass' | 'taxStatus' | 'amount'; + +/** + * Order coupon properties + */ +export type OrderCouponUpdateParams = 'code' | 'discount' | 'discountTax'; + +/** + * Order refund properties + */ +export type OrderRefundUpdateParams = 'reason' | 'total'; From 1664ece7eb3ff04a76ad97d53b579772768d013a Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Mon, 8 Mar 2021 09:59:46 -0400 Subject: [PATCH 006/249] use valid tax status on fees --- tests/e2e/api/src/models/orders/shared/classes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/api/src/models/orders/shared/classes.ts b/tests/e2e/api/src/models/orders/shared/classes.ts index 3852519b94c..c506f6563cc 100644 --- a/tests/e2e/api/src/models/orders/shared/classes.ts +++ b/tests/e2e/api/src/models/orders/shared/classes.ts @@ -335,7 +335,7 @@ export class OrderFeeLine extends OrderItemMeta { * * @type {TaxStatus} */ - public readonly taxStatus: TaxStatus = ''; + public readonly taxStatus: TaxStatus = 'taxable'; /** * The total amount for this fee. From 1cda09d2607e46004d0e1a9a988db4d0bfcbe741 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Tue, 9 Mar 2021 11:33:29 -0400 Subject: [PATCH 007/249] fix api package build errors --- tests/e2e/api/src/framework/model-repository.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/e2e/api/src/framework/model-repository.ts b/tests/e2e/api/src/framework/model-repository.ts index ca598404b93..9c30993a83a 100644 --- a/tests/e2e/api/src/framework/model-repository.ts +++ b/tests/e2e/api/src/framework/model-repository.ts @@ -401,7 +401,7 @@ export class ModelRepository< T extends ModelRepositoryParams > implements } return ( this.listHook as ListChildFn< T > )( - paramsOrParent as ParentID< T >, + ( paramsOrParent as unknown ) as ParentID< T >, params, ); } @@ -428,7 +428,7 @@ export class ModelRepository< T extends ModelRepositoryParams > implements } return ( this.createHook as CreateChildFn< T > )( - propertiesOrParent as ParentID, + ( propertiesOrParent as unknown ) as ParentID, properties as Partial< ModelClass >, ); } @@ -455,7 +455,7 @@ export class ModelRepository< T extends ModelRepositoryParams > implements } return ( this.readHook as ReadChildFn< T > )( - idOrParent as ParentID< T >, + ( idOrParent as unknown ) as ParentID< T >, childID, ); } @@ -480,14 +480,14 @@ export class ModelRepository< T extends ModelRepositoryParams > implements if ( properties === undefined ) { return ( this.updateHook as UpdateFn< T > )( idOrParent as ModelID, - propertiesOrChildID as UpdateParams< T >, + ( propertiesOrChildID as unknown ) as UpdateParams< T >, ); } return ( this.updateHook as UpdateChildFn< T > )( - idOrParent as ParentID< T >, + ( idOrParent as unknown ) as ParentID< T >, propertiesOrChildID as ModelID, - properties, + ( properties as unknown ) as UpdateParams< T >, ); } @@ -513,7 +513,7 @@ export class ModelRepository< T extends ModelRepositoryParams > implements } return ( this.deleteHook as DeleteChildFn< T > )( - idOrParent as ParentID< T >, + ( idOrParent as unknown ) as ParentID< T >, childID, ); } From 2c1b3b52a91267b45641c5325cc0b3d8961661d0 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Thu, 11 Mar 2021 09:20:26 -0400 Subject: [PATCH 008/249] add order class and repository --- tests/e2e/api/src/models/orders/index.ts | 1 + tests/e2e/api/src/models/orders/orders.ts | 364 ++++++++++++++++++ .../api/src/models/orders/shared/classes.ts | 4 +- 3 files changed, 367 insertions(+), 2 deletions(-) create mode 100644 tests/e2e/api/src/models/orders/orders.ts diff --git a/tests/e2e/api/src/models/orders/index.ts b/tests/e2e/api/src/models/orders/index.ts index c3da79f741b..de526a0af64 100644 --- a/tests/e2e/api/src/models/orders/index.ts +++ b/tests/e2e/api/src/models/orders/index.ts @@ -1 +1,2 @@ export * from './shared'; +export * from './orders'; diff --git a/tests/e2e/api/src/models/orders/orders.ts b/tests/e2e/api/src/models/orders/orders.ts new file mode 100644 index 00000000000..04fd8a93282 --- /dev/null +++ b/tests/e2e/api/src/models/orders/orders.ts @@ -0,0 +1,364 @@ +//import { HTTPClient } from '../../http'; +//import { orderRESTRepository } from '../../repositories'; +import { + ModelRepositoryParams, + CreatesModels, + ListsModels, + ReadsModels, + UpdatesModels, + DeletesModels, +} from '../../framework'; +import { + OrderAddressUpdateParams, + OrderCouponUpdateParams, + OrderDataUpdateParams, + OrderFeeUpdateParams, + OrderLineItemUpdateParams, + OrderRefundUpdateParams, + OrderShippingUpdateParams, + OrderTaxUpdateParams, + OrderTotalUpdateParams, + OrderItemMeta, + OrderAddress, + OrderCouponLine, + OrderFeeLine, + OrderLineItem, + OrderRefundLine, + OrderShippingLine, + OrderStatus, + OrderTaxRate, +} from './shared'; +import { ObjectLinks } from '../shared-types'; + +/** + * The parameters that orders can update. + */ +type OrderUpdateParams = OrderAddressUpdateParams + & OrderCouponUpdateParams + & OrderDataUpdateParams + & OrderFeeUpdateParams + & OrderLineItemUpdateParams + & OrderRefundUpdateParams + & OrderShippingUpdateParams + & OrderTaxUpdateParams + & OrderTotalUpdateParams; + +/** + * The parameters embedded in this generic can be used in the ModelRepository in order to give + * type-safety in an incredibly granular way. + */ +export type OrderRepositoryParams = ModelRepositoryParams< Order, never, never, OrderUpdateParams >; + +/** + * An interface for creating coupons using the repository. + * + * @typedef CreatesCoupons + * @alias CreatesModels. + */ +export type CreatesCoupons = CreatesModels< OrderRepositoryParams >; + +/** + * An interface for reading coupons using the repository. + * + * @typedef ReadsCoupons + * @alias ReadsModels. + */ +export type ReadsCoupons = ReadsModels< OrderRepositoryParams >; + +/** + * An interface for updating coupons using the repository. + * + * @typedef UpdatesCoupons + * @alias UpdatesModels. + */ +export type UpdatesCoupons = UpdatesModels< OrderRepositoryParams >; + +/** + * An interface for listing coupons using the repository. + * + * @typedef ListsCoupons + * @alias ListsModels. + */ +export type ListsCoupons = ListsModels< OrderRepositoryParams >; + +/** + * An interface for deleting coupons using the repository. + * + * @typedef DeletesCoupons + * @alias DeletesModels. + */ +export type DeletesCoupons = DeletesModels< OrderRepositoryParams >; + +/** + * A coupon object. + */ +export class Order extends OrderItemMeta { + /** + * The parent order id. + * + * @type {number} + */ + public readonly parentId: number = 0; + + /** + * The order status. + * + * @type {string} + */ + public readonly status: OrderStatus = ''; + + /** + * The order currency. + * + * @type {string} + */ + public readonly currency: string = ''; + + /** + * The WC version used to create the order. + * + * @type {string} + */ + public readonly version: string = ''; + + /** + * Flags if the prices include tax. + * + * @type {boolean} + */ + public readonly pricesIncludeTax: boolean = false; + + /** + * The total of the discounts on the order. + * + * @type {string} + */ + public readonly discountTotal: string = ''; + + /** + * The total of the tax on discounts on the order. + * + * @type {string} + */ + public readonly discountTax: string = ''; + + /** + * The total of the shipping on the order. + * + * @type {string} + */ + public readonly shippingTotal: string = ''; + + /** + * The total of the tax on shipping on the order. + * + * @type {string} + */ + public readonly shippingTax: string = ''; + + /** + * The total cart tax on the order. + * + * @type {string} + */ + public readonly cartTax: string = ''; + + /** + * The total for the order including adjustments. + * + * @type {string} + */ + public readonly total: string = ''; + + /** + * The total tax for the order including adjustments. + * + * @type {string} + */ + public readonly totalTax: string = ''; + + /** + * The customer id. + * + * @type {number} + */ + public readonly customerId: number = 0; + + /** + * A unique key assigned to the order. + * + * @type {string} + */ + public readonly orderKey: string = ''; + + /** + * The billing address. + * + * @type {OrderAddress} + */ + public readonly billing: OrderAddress | null = null; + + /** + * The shipping address. + * + * @type {OrderAddress} + */ + public readonly shipping: OrderAddress | null = null; + + /** + * Name of the payment method. + * + * @type {string} + */ + public readonly paymentMethod: string = ''; + + /** + * Title of the payment method + * + * @type {string} + */ + public readonly paymentMethodTitle: string = ''; + + /** + * Payment transaction ID. + * + * @type {string} + */ + public readonly transactionId: string = ''; + + /** + * Customer IP address. + * + * @type {string} + */ + public readonly customerIpAddress: string = ''; + + /** + * Customer web browser user agent. + * + * @type {string} + */ + public readonly customerUserAgent: string = ''; + + /** + * Method used to create the order. + * + * @type {string} + */ + public readonly createdVia: string = ''; + + /** + * Customer note. + * + * @type {string} + */ + public readonly customerNote: string = ''; + + /** + * Date the order was completed. + * + * @type {string} + */ + public readonly dateCompleted: Date | null = null; + + /** + * Date the order was paid. + * + * @type {string} + */ + public readonly datePaid: Date | null = null; + + /** + * Hash of the cart's contents. + * + * @type {string} + */ + public readonly cartHash: string = ''; + + /** + * Number assigned to the order. + * + * @type {string} + */ + public readonly orderNumber: string = ''; + + /** + * Currency symbol for the order. + * + * @type {string} + */ + public readonly currencySymbol: string = ''; + + /** + * The order's line items. + * + * @type {ReadonlyArray.} + */ + public readonly lineItems: OrderLineItem[] = []; + + /** + * The order's tax rates. + * + * @type {ReadonlyArray.} + */ + public readonly taxLines: OrderTaxRate[] = []; + + /** + * The order's shipping charges. + * + * @type {ReadonlyArray.} + */ + public readonly shippingLines: OrderShippingLine[] = []; + + /** + * The order's fees. + * + * @type {ReadonlyArray.} + */ + public readonly feeLines: OrderFeeLine[] = []; + + /** + * The coupons used on the order. + * + * @type {ReadonlyArray.} + */ + public readonly couponLines: OrderCouponLine[] = []; + + /** + * The refunds to the order. + * + * @type {ReadonlyArray.} + */ + public readonly refunds: OrderRefundLine[] = []; + + /** + * The order's links. + * + * @type {ReadonlyArray.} + */ + public readonly links: ObjectLinks = { + collection: [ { href: '' } ], + self: [ { href: '' } ], + }; + + /** + * Creates a new coupon instance with the given properties + * + * @param {Object} properties The properties to set in the object. + */ + public constructor( properties?: Partial< Order > ) { + super(); + Object.assign( this, properties ); + } + /* + /** + * Returns the repository for interacting with this type of model. + * + * @param {HTTPClient} httpClient The client for communicating via HTTP. + */ + /* + public static restRepository( httpClient: HTTPClient ): ReturnType< typeof orderRESTRepository > { + return orderRESTRepository( httpClient ); + } + */ +} diff --git a/tests/e2e/api/src/models/orders/shared/classes.ts b/tests/e2e/api/src/models/orders/shared/classes.ts index c506f6563cc..f26923edcd5 100644 --- a/tests/e2e/api/src/models/orders/shared/classes.ts +++ b/tests/e2e/api/src/models/orders/shared/classes.ts @@ -169,14 +169,14 @@ export class OrderLineItem extends OrderItemMeta { public readonly subtotalTax: string = ''; /** - * The total for the product including adjusments. + * The total for the product including adjustments. * * @type {string} */ public readonly total: string = ''; /** - * The total tax for the product including adjusments. + * The total tax for the product including adjustments. * * @type {string} */ From e5341ae237196989a94a8b850ddb31558e115a72 Mon Sep 17 00:00:00 2001 From: Chris Diehl Date: Wed, 7 Apr 2021 22:47:12 -0400 Subject: [PATCH 009/249] Updates standardization from ISO to CLDR --- i18n/states.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/i18n/states.php b/i18n/states.php index 25fdd505ba8..d77b05248e9 100644 --- a/i18n/states.php +++ b/i18n/states.php @@ -1736,9 +1736,8 @@ return array( 'AP' => __( 'Armed Forces (AP)', 'woocommerce' ), ), 'VE' => array( // Venezuela States. Ref: https://en.wikipedia.org/wiki/ISO_3166-2:VE - 'W' => __( 'Dependencias Federales', 'woocommerce' ), - 'A' => __( 'Distrito Capital', 'woocommerce' ), - 'Z' => __( 'Amazonas', 'woocommerce' ), + + 'A' => __( 'Capital', 'woocommerce' ), 'B' => __( 'Anzoátegui', 'woocommerce' ), 'C' => __( 'Apure', 'woocommerce' ), 'D' => __( 'Aragua', 'woocommerce' ), @@ -1746,7 +1745,6 @@ return array( 'F' => __( 'Bolívar', 'woocommerce' ), 'G' => __( 'Carabobo', 'woocommerce' ), 'H' => __( 'Cojedes', 'woocommerce' ), - 'Y' => __( 'Delta Amacuro', 'woocommerce' ), 'I' => __( 'Falcón', 'woocommerce' ), 'J' => __( 'Guárico', 'woocommerce' ), 'K' => __( 'Lara', 'woocommerce' ), @@ -1758,9 +1756,12 @@ return array( 'R' => __( 'Sucre', 'woocommerce' ), 'S' => __( 'Táchira', 'woocommerce' ), 'T' => __( 'Trujillo', 'woocommerce' ), - 'X' => __( 'La Guaira', 'woocommerce' ), 'U' => __( 'Yaracuy', 'woocommerce' ), 'V' => __( 'Zulia', 'woocommerce' ), + 'W' => __( 'Federal Dependencies', 'woocommerce' ), + 'X' => __( 'Vargas', 'woocommerce' ), + 'Y' => __( 'Delta Amacuro', 'woocommerce' ), + 'Z' => __( 'Amazonas', 'woocommerce' ) ), 'VN' => array(), 'YT' => array(), From e1c6c540d72ad3de6a0f0116ca8d6064d7f3ed15 Mon Sep 17 00:00:00 2001 From: roykho Date: Fri, 9 Apr 2021 05:33:06 -0700 Subject: [PATCH 010/249] Convert notices to use native nonce generation from WC Admin --- includes/admin/class-wc-admin-notices.php | 45 ------------------- .../notes/class-wc-notes-run-db-update.php | 41 ++++++++++------- includes/class-woocommerce.php | 1 - 3 files changed, 24 insertions(+), 63 deletions(-) diff --git a/includes/admin/class-wc-admin-notices.php b/includes/admin/class-wc-admin-notices.php index fa9716cc498..70c76ee6120 100644 --- a/includes/admin/class-wc-admin-notices.php +++ b/includes/admin/class-wc-admin-notices.php @@ -64,51 +64,6 @@ class WC_Admin_Notices { } } - /** - * Parses query to create nonces when available. - * - * @param object $response The WP_REST_Response we're working with. - * @return object $response The prepared WP_REST_Response object. - */ - public static function prepare_note_with_nonce( $response ) { - if ( 'wc-update-db-reminder' !== $response->data['name'] || ! isset( $response->data['actions'] ) ) { - return $response; - } - - foreach ( $response->data['actions'] as $action_key => $action ) { - $url_parts = ! empty( $action->query ) ? wp_parse_url( $action->query ) : ''; - - if ( ! isset( $url_parts['query'] ) ) { - continue; - } - - wp_parse_str( $url_parts['query'], $params ); - - if ( array_key_exists( '_nonce_action', $params ) && array_key_exists( '_nonce_name', $params ) ) { - $org_params = $params; - - // Check to make sure we're acting on the whitelisted nonce actions. - if ( 'wc_db_update' !== $params['_nonce_action'] && 'woocommerce_hide_notices_nonce' !== $params['_nonce_action'] ) { - continue; - } - - unset( $org_params['_nonce_action'] ); - unset( $org_params['_nonce_name'] ); - - $url = $url_parts['scheme'] . '://' . $url_parts['host'] . $url_parts['path']; - - $nonce = array( $params['_nonce_name'] => wp_create_nonce( $params['_nonce_action'] ) ); - $merged_params = array_merge( $nonce, $org_params ); - $parsed_query = add_query_arg( $merged_params, $url ); - - $response->data['actions'][ $action_key ]->query = $parsed_query; - $response->data['actions'][ $action_key ]->url = $parsed_query; - } - } - - return $response; - } - /** * Store notices to DB */ diff --git a/includes/admin/notes/class-wc-notes-run-db-update.php b/includes/admin/notes/class-wc-notes-run-db-update.php index 1fad100ff9e..77017ec2ca2 100644 --- a/includes/admin/notes/class-wc-notes-run-db-update.php +++ b/includes/admin/notes/class-wc-notes-run-db-update.php @@ -109,24 +109,23 @@ class WC_Notes_Run_Db_Update { * @return int Created/Updated note id */ private static function update_needed_notice( $note_id = null ) { - $update_url = html_entity_decode( + $update_url = add_query_arg( array( 'do_update_woocommerce' => 'true', - '_nonce_action' => 'wc_db_update', - '_nonce_name' => 'wc_db_update_nonce', ), wc_get_current_admin_url() ? wc_get_current_admin_url() : admin_url( 'admin.php?page=wc-settings' ) - ) - ); + ); $note_actions = array( array( - 'name' => 'update-db_run', - 'label' => __( 'Update WooCommerce Database', 'woocommerce' ), - 'url' => $update_url, - 'status' => 'unactioned', - 'primary' => true, + 'name' => 'update-db_run', + 'label' => __( 'Update WooCommerce Database', 'woocommerce' ), + 'url' => $update_url, + 'status' => 'unactioned', + 'primary' => true, + 'nonce_action' => 'wc_db_update', + 'nonce_name' => 'wc_db_update_nonce', ), array( 'name' => 'update-db_learn-more', @@ -166,6 +165,10 @@ class WC_Notes_Run_Db_Update { $note->clear_actions(); foreach ( $note_actions as $note_action ) { $note->add_action( ...array_values( $note_action ) ); + + if ( isset( $note_action['nonce_action'] ) ) { + $note->add_nonce_to_action( $note_action['name'], $note_action['nonce_action'], $note_action['nonce_name'] ); + } } return $note->save(); @@ -212,8 +215,6 @@ class WC_Notes_Run_Db_Update { add_query_arg( array( 'wc-hide-notice' => 'update', - '_nonce_action' => 'woocommerce_hide_notices_nonce', - '_nonce_name' => '_wc_notice_nonce', ), wc_get_current_admin_url() ? remove_query_arg( 'do_update_woocommerce', wc_get_current_admin_url() ) : admin_url( 'admin.php?page=wc-settings' ) ) @@ -221,11 +222,13 @@ class WC_Notes_Run_Db_Update { $note_actions = array( array( - 'name' => 'update-db_done', - 'label' => __( 'Thanks!', 'woocommerce' ), - 'url' => $hide_notices_url, - 'status' => 'actioned', - 'primary' => true, + 'name' => 'update-db_done', + 'label' => __( 'Thanks!', 'woocommerce' ), + 'url' => $hide_notices_url, + 'status' => 'actioned', + 'primary' => true, + 'nonce_action' => 'woocommerce_hide_notices_nonce', + 'nonce_name' => '_wc_notice_nonce', ), ); @@ -242,6 +245,10 @@ class WC_Notes_Run_Db_Update { $note->clear_actions(); foreach ( $note_actions as $note_action ) { $note->add_action( ...array_values( $note_action ) ); + + if ( isset( $note_action['nonce_action'] ) ) { + $note->add_nonce_to_action( $note_action['name'], $note_action['nonce_action'], $note_action['nonce_name'] ); + } } $note->save(); diff --git a/includes/class-woocommerce.php b/includes/class-woocommerce.php index be2df455f7d..b25315cbcf6 100644 --- a/includes/class-woocommerce.php +++ b/includes/class-woocommerce.php @@ -203,7 +203,6 @@ final class WooCommerce { add_action( 'switch_blog', array( $this, 'wpdb_table_fix' ), 0 ); add_action( 'activated_plugin', array( $this, 'activated_plugin' ) ); add_action( 'deactivated_plugin', array( $this, 'deactivated_plugin' ) ); - add_filter( 'woocommerce_rest_prepare_note', array( 'WC_Admin_Notices', 'prepare_note_with_nonce' ) ); // These classes set up hooks on instantiation. wc_get_container()->get( DownloadPermissionsAdjuster::class ); From 6ed847a7b9fa1f30442281d0e50bfc81aa6f799a Mon Sep 17 00:00:00 2001 From: roykho Date: Tue, 13 Apr 2021 19:53:00 -0700 Subject: [PATCH 011/249] Deprecate method instead of removing it --- includes/admin/class-wc-admin-notices.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/includes/admin/class-wc-admin-notices.php b/includes/admin/class-wc-admin-notices.php index 70c76ee6120..b543c698472 100644 --- a/includes/admin/class-wc-admin-notices.php +++ b/includes/admin/class-wc-admin-notices.php @@ -64,6 +64,19 @@ class WC_Admin_Notices { } } + /** + * Parses query to create nonces when available. + * + * @deprecated 5.4.0 + * @param object $response The WP_REST_Response we're working with. + * @return object $response The prepared WP_REST_Response object. + */ + public static function prepare_note_with_nonce( $response ) { + wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '5.4.0' ); + + return $response; + } + /** * Store notices to DB */ From edd8f545df59249bf80d678d5b07fa41163bb230 Mon Sep 17 00:00:00 2001 From: Bero Date: Fri, 16 Apr 2021 11:54:10 +0200 Subject: [PATCH 012/249] Always search all addons --- includes/admin/views/html-admin-page-addons.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/admin/views/html-admin-page-addons.php b/includes/admin/views/html-admin-page-addons.php index ceea4ec99e5..3a8dd3648ed 100644 --- a/includes/admin/views/html-admin-page-addons.php +++ b/includes/admin/views/html-admin-page-addons.php @@ -56,8 +56,7 @@ if ( ! defined( 'ABSPATH' ) ) { value="" placeholder=""> - - +