Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(product-duplicator): Copy tax category on variants #2947

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion packages/core/e2e/duplicate-entity.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ describe('Duplicating entities', () => {

duplicateEntityGuard.assertSuccess(duplicateEntity);
const variant = product?.variants.find(v => v.sku.startsWith(originalFirstVariant.sku));
// console.log('pv1', duplicateEntity.newEntityId, product!.variants, variant)
expect(variant).not.toBeUndefined();
expect(originalFirstVariant.price).toBeGreaterThan(0);
expect(variant!.price).toBe(originalFirstVariant.price);
Expand Down Expand Up @@ -676,6 +675,52 @@ describe('Duplicating entities', () => {

expect(productVariantChannel2!.price).toEqual(productVariant.price + 150);
});

it('tax categories are duplicated', async () => {
// update existing variant with a non 1 first tax category
// bc tax category defaults to the first available
const { product } = await adminClient.query<
Codegen.GetProductWithVariantsQuery,
Codegen.GetProductWithVariantsQueryVariables
>(GET_PRODUCT_WITH_VARIANTS, {
id: 'T_1',
});
const { updateProductVariants } = await adminClient.query<
Codegen.UpdateProductVariantsMutation,
Codegen.UpdateProductVariantsMutationVariables
>(UPDATE_PRODUCT_VARIANTS, {
input: [{ id: product!.variants[0].id, taxCategoryId: 'T_2' }],
});
const { duplicateEntity } = await adminClient.query<
Codegen.DuplicateEntityMutation,
Codegen.DuplicateEntityMutationVariables
>(DUPLICATE_ENTITY, {
input: {
entityName: 'Product',
entityId: 'T_1',
duplicatorInput: {
code: 'product-duplicator',
arguments: [
{
name: 'includeVariants',
value: 'true',
},
],
},
},
});
const { product: productReloaded } = await adminClient.query<
Codegen.GetProductWithVariantsQuery,
Codegen.GetProductWithVariantsQueryVariables
>(GET_PRODUCT_WITH_VARIANTS, {
id: duplicateEntity.newEntityId,
});
const variant = productReloaded?.variants.find(v =>
v.sku.startsWith(product!.variants[0].sku),
);
expect(variant).not.toBeUndefined();
expect(variant!.taxCategory.id).toEqual('T_2');
});
});

describe('Collection duplicator', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export const productDuplicator = new EntityDuplicator({
stockLevels: true,
facetValues: true,
productVariantPrices: true,
taxCategory: true,
},
});
if (product.optionGroups && product.optionGroups.length) {
Expand Down Expand Up @@ -167,13 +168,13 @@ export const productDuplicator = new EntityDuplicator({
const price =
variant.productVariantPrices.find(p => idsAreEqual(p.channelId, ctx.channelId))?.price ??
variant.productVariantPrices[0]?.price;

return {
productId: duplicatedProduct.id,
price: price ?? variant.price,
sku: `${variant.sku}-copy`,
stockOnHand: 1,
featuredAssetId: variant.featuredAsset?.id,
taxCategoryId: variant.taxCategory?.id,
useGlobalOutOfStockThreshold: variant.useGlobalOutOfStockThreshold,
trackInventory: variant.trackInventory,
assetIds: variant.assets.map(value => value.assetId),
Expand Down
Loading