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 broken product image URLs in order confirmation email #3131

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nirzaf
Copy link

@nirzaf nirzaf commented Oct 13, 2024

Fixes #3130

Update the order service and resolver to include the lines.featuredAsset relation.

  • Order Service

    • Add lines.featuredAsset to the relations array in the findOne method in packages/core/src/service/services/order.service.ts.
  • Order Resolver

    • Add lines.featuredAsset to the relations array in the order query in packages/core/src/api/resolvers/admin/order.resolver.ts.

Fixes vendure-ecommerce#3130

Update the order service and resolver to include the `lines.featuredAsset` relation.

* **Order Service**
  - Add `lines.featuredAsset` to the relations array in the `findOne` method in `packages/core/src/service/services/order.service.ts`.

* **Order Resolver**
  - Add `lines.featuredAsset` to the relations array in the `order` query in `packages/core/src/api/resolvers/admin/order.resolver.ts`.
Copy link

vercel bot commented Oct 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview Oct 13, 2024 8:21am

Copy link
Contributor


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@michaelbromley
Copy link
Member

Hi, thanks for reporting the issue and providing a fix!

I think that we can fix this without having to touch the core service & resolver. I'd rather see a solution which modifies just the email handler, and use the EntityHydrator there to make sure the line featured assets are hydrated.

Would you be able to update this PR to solve it that way?

@HerclasNido
Copy link
Contributor

HerclasNido commented Dec 24, 2024

Hi,
In the orderConfirmationHandler, when calling the function transformOrderLineAssetUrls(), toAbsoluteUrl() is used but seems to return the absolute url with an extra '/'.

Below, when I log the result and generate a test email I get: "http://localhost:3000/assets//mailbox/placeholder-image"
Maybe the bug comes from assetStorageStrategy.toAbsoluteUrl? I'm not sure how to approach this problem.

export function transformOrderLineAssetUrls(
    ctx: RequestContext,
    order: Order,
    injector: Injector
): Order {
    const { assetStorageStrategy } = injector.get(ConfigService).assetOptions;
    if (assetStorageStrategy.toAbsoluteUrl) {
        const toAbsoluteUrl =
            assetStorageStrategy.toAbsoluteUrl.bind(assetStorageStrategy);
        for (const line of order.lines) {
            if (line.featuredAsset) {
                const absolute = toAbsoluteUrl(ctx.req as Request, line.featuredAsset.preview);
                console.log(absolute);
                line.featuredAsset.preview = absolute;
                // line.featuredAsset.preview = toAbsoluteUrl(
                //     ctx.req as Request,
                //     line.featuredAsset.preview
                // );
            }
        }
    }
    return order;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Product image urls is broken in order confirmation email
3 participants