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 to add multiple Items of the same core product ID #83

Open
wizyoua opened this issue Dec 7, 2016 · 1 comment
Open

How to add multiple Items of the same core product ID #83

wizyoua opened this issue Dec 7, 2016 · 1 comment

Comments

@wizyoua
Copy link

wizyoua commented Dec 7, 2016

So in my application we are using ng-cart but I'll make a simple example to show how you can make the application more powerful:

Say you have 3 Items:
Iphone1 Iphone2 Iphone3

ng-cart has the "add to cart" button which will add say Iphone 1 to the cart

the id:of Iphone 1 lets say is id="1"

But what if the application has more options to choose like color, size, carrier. Well after passing that object into the data="{...}" attribute, we need to be able to add a unique Iphone1 to the cart so that every time you click add to cart a unique item is added to the checkout screen.

All you have to do is go into ngCart.js file - Line 213

this line grabs the initial id before even doing anything else in the program

 item.prototype.setId = function(id){
    if (id)  this._id = id;
        else {
            $log.error('An ID must be provided');
        }
    }

In my case I wanted to simply append some number to differentiate every item that I click "add to cart" with so I did:

item.prototype.setId = function(id){
        //create Unique Id here
        //get millisecond var
        var timestamp = new Date().getUTCMilliseconds();
        //append mill var with id var to create unique id
        if (id)  this._id = id + timestamp;
        else {
            $log.error('An ID must be provided');
        }
    }; 

Now you can go and add a item to the cart, click checkout and check console. You will see the id of that item be appended with 3 more numbers.

Current Thoughts on this:

  • I think this is a good work around since if you need to add more of the same kind you can just click the + in the check out screen
  • One thing that happens is even if you have the same item + same data it will still be a unique iditem so in the checkout screen you will keep adding a new item everytime, Which may work for you or not.
@wizyoua wizyoua changed the title How to add multiple Items of the same ID How to add multiple Items of the same core product ID Dec 9, 2016
@Voronov
Copy link

Voronov commented Dec 24, 2016

if you have iphone 1 with options e. g. size of memory 32, 64, 128 or with colors green, red, blue. You can make id for ngCart by adding them to id, Example: If you have id="1" for your iphone id can be id+size+color and it will be 132red. It will be unique and repeatable if user will try to add again.

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