1

I read through the docs for Commerce, but could not figure out how to use Purchase Orders with Commerce. I am still working through the trial version to make sure Commerce can do what the client is wanting. I know the paid version has a manual gateway. Want to make sure it will allow the collection of a Purchase Order.

Jeremy I tried what you suggest. Here is what I have...

    {% if not craft.commerce.paymentMethods|length %}
        <p>No payment methods available.</p>
    {% endif %}

    {% if craft.commerce.paymentMethods|length %}
        <form method="POST" id="paymentMethod" class="form-inline">

            <input type="hidden" name="action" value="commerce/cart/updateCart">
            <input type="hidden" name="redirect" value="commerce/checkout/payment">

            {{ getCsrfInput() }}

            <label for="">Payment Method</label><br >
            <select id="paymentMethodId" name="paymentMethodId"
                    class="form-control">
                {% for id,name in craft.commerce.paymentMethods %}
                    <option value="{{ id }}"
                            {% if id == cart.paymentMethod.id %}selected{% endif %}>{{ name }}</option>
                {% endfor %}
            </select>

            <div class="purchase-order-block">
                <label>Purchase Order Number</label>
                <input type="text" name="purchaseOrder"
                    placeholder="Purchase Order"
                    class="purchase-order-field"
                    value="{{ formValues.lastName }}">
            </div>

        </form>
    {% endif %}

I am not surprised that it is not working as I really don't know what I am doing here. Sure my form is wrong. Any suggestions. With your help on other areas I am almost finished. This is the last thing I need to do and I will be finished. Any suggestions or help will be greatly appreciated.

1

There are many ways to skin this particular cat I'm sure, but the easiest way is just to use the manual payment gateway and a/some custom field(s) on your order to record the purchase order details.

Whenever you call the updateCart controller, from your input form where you gather the PO details, you can then pass in the POST parameters as fields[purchaseOrderDetails] to save the data to your field named purchaseOrderDetails for later processing.

Update using your code above:

{% if not craft.commerce.paymentMethods|length %}
    <p>No payment methods available.</p>
{% endif %}

{% if craft.commerce.paymentMethods|length %}
    <form method="POST" id="paymentMethod" class="form-inline">

        <input type="hidden" name="action" value="commerce/cart/updateCart">
        <input type="hidden" name="redirect" value="commerce/checkout/payment">

        {{ getCsrfInput() }}

        <label for="">Payment Method</label><br >
        <select id="paymentMethodId" name="paymentMethodId"
                class="form-control">
            {% for id,name in craft.commerce.paymentMethods %}
                <option value="{{ id }}"
                        {% if id == cart.paymentMethod.id %}selected{% endif %}>{{ name }}</option>
            {% endfor %}
        </select>

        <div class="purchase-order-block">
            <label>Purchase Order Number</label>
            <input type="text" name="fields[purchaseOrder]"
                placeholder="Purchase Order"
                class="purchase-order-field"
                value="{{ cart.purchaseOrder }}">
        </div>

    </form>
{% endif %}

All I have really done here is change how you're referencing the filed on our order (which must have a handle of purchaseOrder for the above to work). And I am presuming you have the cart available in cart obviously.

Don't forget to accept the answer if it gets you going! Untested, but that's pretty much it, you were almost there really!

| improve this answer | |
  • One more thing - with these sorts of fields I like to make them incognito fields (indeed I did a PR wit this to improve their behaviour, but hasn't been merged yet) - github.com/mmikkel/IncognitoField-Craft - basically this can make a field non-editable to your order processing people can't accidentally over-write the customer submitted data. – Jeremy Daalder May 20 '16 at 5:53
  • I may be approaching this wrong. I am wanting the PO to listed in the Commerce>Orders> so that when I am logged in I will be able to see the PO. Right now the field is blank. – user1663102 May 20 '16 at 16:48
  • Custom fields on orders should be visible in the back end, if that is what you mean. Basically, you can define any custom field type you want, and then you add it to the order fields in Commerce->settings. You can do all the normal field layout stuff (tabs etc) - and these fields will appear below the order when you're looking at that order in the commerce back end. If you want it listed on just the Commerce -> Orders page itself, rather than a specific order, just click on the cog icon belowyour order statusses and add it as a column there. – Jeremy Daalder May 21 '16 at 0:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.