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

[4.3.1]: EVENT_MODIFY_CART_INFO broken (Ajax getCart()) #3311

Closed
Mathias-Syversen opened this issue Oct 23, 2023 · 0 comments
Closed

[4.3.1]: EVENT_MODIFY_CART_INFO broken (Ajax getCart()) #3311

Mathias-Syversen opened this issue Oct 23, 2023 · 0 comments
Assignees
Labels
bug commerce4 Issues related to Commerce v4

Comments

@Mathias-Syversen
Copy link

What happened?

Description

I've used an event to add an bakeries and stores to the cart, so check what products to display based on chosen store, and if line items needs to be removed when swapping stores, based on the store's related bakery.

This has worked on Commerce 3 for years, and up until the latest Commerce update worked great on Commerce 4.
Now, it seems no custom fields from EVENT_MODIFY_CART_INFO is represented on the json output from the ajax / getCart controller. Even the example on https://craftcms.com/docs/commerce/4.x/extend/events.html#modifycartinfo is broken.

This is my current code:

`Event::on(BaseFrontEndController::class, BaseFrontEndController::EVENT_MODIFY_CART_INFO, function(ModifyCartInfoEvent $e) {
$currentUser = Craft::$app->getUser()->getIdentity();
$cartArray = $e->cartInfo;

$cartArray['fields']['store'] = ['id' => 0, 'title' => 'Ingen butikk valgt'];
$cartArray['fields']['bakery'] = ['id' => 0, 'title' => 'Bakeri ikke valgt'];
$cartArray['fields']['currentUser'] = false;

if ($cartArray['id']) {
    $cart = Order::find()->id($cartArray['id'])->one();
    $bakery = $cart->orderBakery->one();
    $store = $cart->orderStore->one();
    
    $cartArray['fields']['store'] = $store ? ['id' => $store->id, 'title' => $store->title] :  $cartArray['fields']['store'];
    $cartArray['fields']['bakery'] = $bakery ? ['id' => $bakery->id, 'title' => $bakery->title] :  $cartArray['fields']['bakery'];
}

$e->cartInfo = $cartArray;

});`

In addition, orderStore and orderBakery is now represented directly on the order, as something that looks like an element query?

orderBakery: {select: {**: "**"}, selectOption: null, distinct: false, from: null, groupBy: null, join: [,…],…}

Steps to reproduce

Try example from https://craftcms.com/docs/commerce/4.x/extend/events.html#modifycartinfo,
get cart with js / ajax.

Expected behavior

The cart object should have a custom field "fields" with the bakery and store information set in the function.

Actual behavior

All custom fields are missing from the ajax cart object.

Craft CMS version

4.5.8

Craft Commerce version

4.3.1

PHP version

8.2.5

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

@Mathias-Syversen Mathias-Syversen added commerce4 Issues related to Commerce v4 bug labels Oct 23, 2023
@lukeholder lukeholder self-assigned this Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug commerce4 Issues related to Commerce v4
Projects
None yet
Development

No branches or pull requests

2 participants