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

getOrderAdjustments() is empty at email notifications trigger #960

Closed
siebird opened this issue Aug 14, 2019 · 5 comments
Closed

getOrderAdjustments() is empty at email notifications trigger #960

siebird opened this issue Aug 14, 2019 · 5 comments
Labels

Comments

@siebird
Copy link

siebird commented Aug 14, 2019

Currently, we have shipping adjustments made during checkout for our custom shipping plugin. At successful order completion, getOrderAdjustments() is empty when the email notifications are triggered. We're having the same issue with the PDF attachment to the email.

However, viewing the order or downloading the PDF from the CP the shipping adjustments are viewable.

Additional info

  • Craft version: 3.2.9
  • Commerce version: 2.1.10
  • PHP version: 7.3.5
@lukeholder
Copy link
Member

Not sure how that could be happening, is your email triggered by the initial order status change?

@lukeholder lukeholder added the ℹ️ status: need more info When waiting for user to supply database or more information. label Aug 15, 2019
@siebird
Copy link
Author

siebird commented Aug 15, 2019

Yes, by the first order status New

@lukeholder
Copy link
Member

Could you share your code?

@siebird
Copy link
Author

siebird commented Aug 16, 2019

Due to custom shipping logic, we are using adjusters. The adjuster code looks like this:

private function _createShippingAdjustment($shippingAddress, $shippingMethod): OrderAdjustment
{

    $adjustment = new OrderAdjustment;
    $adjustment->type = self::ADJUSTMENT_TYPE_SHIPPING;
    $adjustment->name = $shippingMethod->getName();
    $adjustment->description = "Shipping Rule: " . $shippingMethod->getName() . ". ZipCode: " . $shippingAddress['zipCode'];
    $adjustment->sourceSnapshot = $shippingAddress;
    $adjustment->setOrder($this->_order);
    $adjustment->amount = (is_array($shippingMethod->rate) ? $shippingMethod->rate['amount'] : $shippingMethod->rate);

    return $adjustment;

}

To fetch Shipping methods in PDF, we use this code:

{% for adjustment in order.getOrderAdjustments() %}
    {% if adjustment.type == "shipping" %}
        <tr>
            <td class=""></td>
            <td class=""></td>
            <td class=" text-right">
                {{ adjustment.name }}
                {% set dispatchDate = order.deliveryDate %}
                {% if dispatchDate and not giftCards %}
                    <br>({{ dispatchDate.format('F, jS Y') }}{{ order.shippingMethod.getHandle() == "pickup" ? ' - ' ~ order.pickupTime|default('10:00 AM') }})
                {% endif %}
            </td>
            <td class=" total">{{ adjustment.amount|currency(order.currency) }}</td>
        </tr>
    {% endif %}
{% endfor %}

This code works in the order summary page (the page redirect after order completed)

@lukeholder lukeholder added bug and removed ℹ️ status: need more info When waiting for user to supply database or more information. labels Aug 22, 2019
@lukeholder
Copy link
Member

@siebird Thanks for reporting the issue. It has been fixed for the next release.

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

No branches or pull requests

2 participants