1class OrderController extends Controller
2{
3
4 public function store(StoreOrderRequest $request, Checkout $checkout)
5 {
6 $order = DB::transaction(fn () => $checkout->place(
7 customer: $request->user(),
8 items: $request->validated('items'),
9 ));
10
11 OrderPlaced::dispatch($order);
12
13 return redirect()->route('orders.show', $order);
14 }
15}
1
2<div class="product-card">
3 <a href="{{ product.url }}">
4 {{ product.featured_image | image_url: width: 600 | image_tag: loading: 'lazy' }}
5 </a>
6 <h3>{{ product.title | escape }}</h3>
7 {% if product.compare_at_price > product.price %}
8 <s>{{ product.compare_at_price | money }}</s>
9 {% endif %}
10 <strong>{{ product.price | money }}</strong>
11</div>
1
2
3add_filter('the_content', function (string $html): string {
4 $keyword = get_post_meta(get_the_ID(), 'focus_keyword', true);
5
6 if (! $keyword) {
7 return $html;
8 }
9
10 return preg_replace('/<img(?![^>]*\balt=)/i', '<img alt="' . esc_attr($keyword) . '"', $html);
11});
1
2export async function stripeWebhook(req, res) {
3 const event = stripe.webhooks.constructEvent(
4 req.rawBody,
5 req.headers['stripe-signature'],
6 process.env.STRIPE_WEBHOOK_SECRET,
7 );
8
9 if (event.type === 'checkout.session.completed') {
10 await orders.markPaid(event.data.object.metadata.orderId);
11 }
12
13 res.json({ received: true });
14}