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

How can i group/bundle products of order.lineItems ? #3

Open
craftcmscoder opened this issue Apr 4, 2017 · 5 comments
Open

How can i group/bundle products of order.lineItems ? #3

craftcmscoder opened this issue Apr 4, 2017 · 5 comments

Comments

@craftcmscoder
Copy link

Is there a way to group products on Order.lineitems. If not please provide a way of doing that.

@nfourtythree
Copy link
Contributor

@craftcmscoder If I follow the question correctly you can use the cartBundle filter that is used on the cart for orders as it is exactly the same structure.

So {% set lineItems = order.lineItems|cartBundle %} should get you what you need.

Hope this helps!

@craftcmscoder
Copy link
Author

craftcmscoder commented Apr 4, 2017

Sorry, it doesn't works. It return the items in the cart only instead of order. Please Help !!

@nfourtythree
Copy link
Contributor

@craftcmscoder hmm interesting I have this exact code working on a couple of sites so this sounds a little strange.

Is there any chance that you could setup a debug template using the code below and send me the output?

In this code please replace REPLACE_ME with an order id that has a bundle purchased in it. You can get the order id from the url in the CMS see here

Debug template

{% set order = craft.commerce.orders.first( { id: REPLACE_ME } ) %}

{% set lineItems = order.lineItems %}
<h3>NOT BUNDLED ROWS: {{ lineItems|length }}</h3>
{% for line in lineItems %}
  <pre>
    ===
    <ul>
      <li>Desc: {{ line.description }}</li>
      <li>options: {{ dump(line.options) }}</li>
    </ul>
    ===
  </pre>
{% endfor %}

{% set lineItems = order.lineItems|cartBundle %}
<h3>BUNDLED ROWS: {{ lineItems|length }}</h3>
{% for line in lineItems %}
  <pre>
    ===
    <ul>
      <li>Desc: {{ line.description }}</li>
      <li>options: {{ dump(line.options) }}</li>
    </ul>
    ===
  </pre>
{% endfor %}

Hopefully this output will help decipher what is going on

@nfourtythree nfourtythree reopened this Apr 4, 2017
@craftcmscoder
Copy link
Author

craftcmscoder commented Apr 4, 2017

Well Something strange happened. The dump twig of line.option inside {% set lineItems = order.lineItems|cartBundle %} outputs 15000 lines of code.But i managed to cut out the option part. Here it is

`

                NOT BUNDLED ROWS: 5
                ===
                

                  
                Desc: Book 1

                  
                options: array(2) {
                  ["bundleId"]=>
                  string(43) "Cl6reZ7NUSH1DbU9ni_gAG-4g5fYyKJwlkR2elxHZ68"
                  ["bundleName"]=>
                  string(18) "Book 1"
                }

                

                ===
              
                ===
                

                  
                Desc: Book 1-2 

                  
                options: array(2) {
                  ["bundleId"]=>
                  string(43) "Cl6reZ7NUSH1DbU9ni_gAG-4g5fYyKJwlkR2elxHZ68"
                  ["bundleName"]=>
                  string(5) "Book 1-2 "
                }

                

                ===
              
                ===
                

                  
                Desc: Book 2

                  
                options: array(2) {
                  ["bundleId"]=>
                  string(43) "UcXMq20uj4YSTaqiK68TrJgHCsCvROpA6lEWe5uEM90"
                  ["bundleName"]=>
                  string(19) "Book 2"
                }

                

                ===
              
                ===
                

                  
                Desc: Book 2-1 

                  
                options: array(2) {
                  ["bundleId"]=>
                  string(43) "UcXMq20uj4YSTaqiK68TrJgHCsCvROpA6lEWe5uEM90"
                  ["bundleName"]=>
                  string(18) "Book 2-1 "
                }

                

                ===
              
                ===
                

                  
                Desc: Book 3 

                  
                options: array(0) {
                }

                

                ===
              
                BUNDLED ROWS: 2
                ===
                

                  
                Desc: Atlas 1              
                options: array(3) {
                  ["bundle"]=>
                  object(Craft\Commerce_ProductModel)#3234 (28) {
                    ["elementType":protected]=>
                    string(16) "Commerce_Product"
                    ["_variants":"Craft\Commerce_ProductModel":private]=>
                    NULL
                    ["_fieldsByHandle":"Craft\BaseElementModel":private]=>
                    NULL
                    ["_contentPostLocation":"Craft\BaseElementModel":private]=>
                    NULL
                    ["_rawPostContent":"Craft\BaseElementModel":private]=>
                    NULL
                    ["_content":"Craft\BaseElementModel":private]=>
                    object(Craft\ContentModel)#3235 (13) {
                      ["_requiredFields":"Craft\ContentModel":private]=>
                      NULL
                      ["_attributeConfigs":"Craft\ContentModel":private]=>
                      array(68) {
                .
                .
                .
                .
                .

                        ["options"]=>
                        array(2) {
                          ["bundleId"]=>
                          string(43) "DIhs8QSu0LR39l3DfP7Zf78NEwuP_neJXDVq_A2tOEg"
                          ["bundleName"]=>
                          string(11) "Discovery "
                        }
                ===
              
                ===
                Desc: Atlas 2
                options: array(3) {
                  ["bundle"]=>
                  .
                  .
                  .
                  .
                  .
                      ["options"]=>
                        array(2) {
                          ["bundleId"]=>
                          string(43) "nWgOMjJxl7mJRczaWZ2aybAQXPYYPnIx1kUI-47YRus"
                          ["bundleName"]=>
                          string(18) "History"
                        }`

NOTE: The items under Bundled row are still coming from the cart

@nfourtythree
Copy link
Contributor

nfourtythree commented Apr 4, 2017

@craftcmscoder I really don't think I follow what is going on here. From this side it looks like things are getting bundled as non-bundled rows are 5 and bundled rows are 2. So the plugin is bundling up some of the products together.

I don't quite understand what you mean by "bundled rows are still coming from the cart" if you used the template in the previous post then they will be coming from an order as you explicitly got the data from an order.

As mentioned before I have this working on a couple of sites in the Cart, Order Summary, Order email etc.

Not sure entirely the best way to proceed with this, one option being allowing me access to the setup (code, db etc) so I could have a look and see what is going on

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

No branches or pull requests

2 participants