signalpoint / commerce

The Drupal Commerce module for DrupalGap.
8 stars 10 forks source link

Adding line items to cart #2

Closed TheDucc closed 8 years ago

TheDucc commented 10 years ago

First of all: Long time listener; First time caller. You are great! Thanks for all the work of yours I have used since I started developing.

I was just creating an account to contribute the 'add line item to cart' work I completed. Then I noticed that you have contributed the code I was working on. (much better than my efforts).

But some of my code I still needed to use and would like to get you take.

Most notably: jDrupal/bin/jdrupal.js From within the Drupal.services.call function the request content type is being overridden from: application/x-www-form-urlencoded to: 'application/json' I added an IF statement to parallel the one for user login

              if (options.service == 'line-item' &&
                options.resource == 'create') {
                content_type = 'application/x-www-form-urlencoded';
              }

I assume you have done something better.

I also had to edit commerce/commerce.js

function _commerce_product_display_get_current_product_id()

In line 328 I needed to hardwire my product reference field before I could get an ID

  $.each(_commerce_product_display['field_product_entities'], function(pid, product) {

But each of these items may be due to remnants of the code I was going to contribute.

I am going to try an move onto the checkout display code now. My goal (I work with chrisschaub) is to effect some form of node checkout; but more like Node Pay, since I am only interested in single purchases that go straight to checkout from the product view.

I started by adding a product reference field to a node.

dmducc

signalpoint commented 10 years ago

@TheDucc thanks for chiming in. For any code that you'd like to contribute, please make a "Fork" of the repository. For example, the jDrupal repo is located here:

https://github.com/easystreet3/jDrupal

I believe the request content type issue has been taken care of in the jDrupal repository, but it hasn't been added back into the DrupalGap repo yet (since the DG repo just holds a .min.js of jDrupal).

As for your issue with the commerce module, please make a fork of that repo too, then clone it out for your use. Then make any changes you need see fit, then you can submit a "pull request" to get the code back into the parent repo.

@chrisschaub should be able to help you with the forks and pull requests.

@scotthooker has started on the checkout stuff as well, maybe he can chime in so duplicate work doesn't happen.

I hope that covers everything you mentioned above, let me know if there is anything else, or create another issue.

TheDucc commented 10 years ago

Yup...jdrupal has also been updated and...in a much saner way. I have never been so happy to spend time on something so unnecessary.

Before move on to checkout (Hi scotthooker), I am going to address the dynamic field name issue. I just want to make sure it is an issue and not poor understanding on my part.

commerce.js Line 136-167

    // @TODO - is this dynamic, or is it a static name chosen by the site builder?
    var product_entities_field_name = 'field_product_entities';

I THINK that this is (mostly) the name of the Product reference field type added to a node. Where 'field_' is a permanent prefix; and '_entities' is a suffix. And then 'product' comes from the field name chosen by the User during Content Type creation.

This logic is reused in

function _commerce_product_display_get_current_product_id()

as I have noted above.

I can think of two ways to get the specific name of the field A: Drilling down into each object and look for the 'type' that matches a known Product Type. B: Use the node type to determine the Product reference field associated with that node.

I am going to try B first.

signalpoint commented 10 years ago

Just an update on this, for the fix, replace the occurences of field_product_entities in commerce.js with the machine name of your product reference field on your product content type.

signalpoint commented 8 years ago

Please disregard any old techniques for fixing this, and now refer to the README for proper configuration to support your custom product reference fields: https://github.com/signalpoint/commerce#drupalgap-setup