Update Shopping Cart - Django Wednesdays ECommerce 17

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 พ.ย. 2024

ความคิดเห็น • 61

  • @Codemycom
    @Codemycom  11 หลายเดือนก่อน +2

    ▶ Watch Django Wednesdays Ecommerce Playlist ✅ Subscribe To My TH-cam Channel:
    bit.ly/3OBQJfN bit.ly/2IGzvOR
    ▶ See More At: ✅ Join My Facebook Group:
    Codemy.com bit.ly/2GFmOBz
    ▶ Learn to Code at Codemy.com ✅ Buy a Codemy T-Shirt!
    Take 50% off with coupon code: youtube50 bit.ly/2VC9WUN
    ▶ Get The Code
    bit.ly/47xAhWJ

  • @myty5563
    @myty5563 4 หลายเดือนก่อน +3

    that little space between ' option:selected' got me thinking for an good 10 minutes hahahaha good series, enjoying it a lot

    • @Codemycom
      @Codemycom  4 หลายเดือนก่อน +1

      Ha

    • @cyanokid4895
      @cyanokid4895 3 หลายเดือนก่อน +1

      fortunately i read this comment. i try this tutorial in a whole day for the update button to work and find out just got messed by a single space 🥲🤣

    • @benjaminmehrez3384
      @benjaminmehrez3384 หลายเดือนก่อน

      @@cyanokid4895 I had this error ahhahhaha for about 1 hour

  • @ΝικόλαςΡιζόπουλος-τ9υ
    @ΝικόλαςΡιζόπουλος-τ9υ 9 หลายเดือนก่อน +2

    Thank you for your very descriptive and understandable videos John! 😀

    • @Codemycom
      @Codemycom  9 หลายเดือนก่อน

      Glad you're enjoying them!

  • @alimalek9362
    @alimalek9362 2 หลายเดือนก่อน

    thank you for great tut. but when I click on a product that before added to cart it isn't add the quantity just I should change it from cart summary. how I can do that.

    • @Codemycom
      @Codemycom  2 หลายเดือนก่อน

      you typed something wrong in your code

  • @delic8107
    @delic8107 11 หลายเดือนก่อน +1

    Is the same procedure for the delete button, because I can try do it by myself :D
    I also add pagination, contact form and update footer.

    • @Codemycom
      @Codemycom  11 หลายเดือนก่อน +2

      Pretty much, slightly different...we'll do that next week.

    • @delic8107
      @delic8107 11 หลายเดือนก่อน +1

      @@Codemycom Thanks, can't wait

  • @Citiciti1717
    @Citiciti1717 9 หลายเดือนก่อน

    Hello sir, if we instead did it service_qty: $('#select'+ serviceid).val(), would it bring an error later on? Because with service_qty: $('#select'+ serviceid+ 'option:selected').text(), it is not working for me
    Thank you in advance, loving this series!

    • @Codemycom
      @Codemycom  9 หลายเดือนก่อน

      No. Code doesn't work for some people and not for you. If the code isn't working, you've done something wrong. Retrace your steps and figure out what that is...in this case, I think you left off a space before ' option:selected')

  • @rickiexie167
    @rickiexie167 5 หลายเดือนก่อน

    I got same error below but I found a typeerror like : product_id: $('this').data('index'),...and I correct it : product_id: $(this).data('index'), This works. Guess I was fooling myself XD
    btw thank you John for doing this tutorial, now I can keep moving forward 👍

    • @Codemycom
      @Codemycom  5 หลายเดือนก่อน

      Glad to hear it!

  • @БогданСокольников-т1н
    @БогданСокольников-т1н 10 หลายเดือนก่อน

    Hi, really cool videos! I noticed that if I try to add something to the cart, logout, and after that try to log in again to the same user, I got an empty cart.

    • @БогданСокольников-т1н
      @БогданСокольников-т1н 10 หลายเดือนก่อน

      Is it only my mistake or this bug that have to be fixed?

    • @Codemycom
      @Codemycom  10 หลายเดือนก่อน +1

      We haven't addressed this yet in the playlist, we only just added the ability to register.

  • @sma1gdz
    @sma1gdz 11 หลายเดือนก่อน +2

    💙💙💙💚💚💚

    • @Codemycom
      @Codemycom  11 หลายเดือนก่อน +1

      🙂

  • @viktorbonilla5509
    @viktorbonilla5509 11 หลายเดือนก่อน

    When i clicked in the quantity drop button, select the value to update and update. My dict update, and everything works, but the value in my quantity label, doesnt. Sorry if i have any mistake in my english.

    • @Codemycom
      @Codemycom  11 หลายเดือนก่อน

      What did you do differently from the video?

    • @viktorbonilla5509
      @viktorbonilla5509 11 หลายเดือนก่อน

      I dont know, but after the problem,i copied view, cart_update and html. And not working yet@@Codemycom

    • @viktorbonilla5509
      @viktorbonilla5509 11 หลายเดือนก่อน

      $(document).on('click', '.update-cart', function (e) {
      e.preventDefault();
      // grab the product id
      var productid = $(this).data('index');
      $.ajax({
      type: 'POST',
      url: '{% url "cart:cart_update" %}',
      data: {
      product_id: $(this).data('index'),
      product_qty: $('#select' + productid + ' option:selected').text(),
      csrfmiddlewaretoken: '{{ csrf_token }}',
      action: 'post'
      },
      success: function (json) {
      //console.log(json)
      //document.getElementById("cart_quantity").textContent = json.qty
      location.reload();
      },
      error: function (xhr, errmsg, err) {
      }
      });
      })

    • @viktorbonilla5509
      @viktorbonilla5509 11 หลายเดือนก่อน

      Quantity:


      {% for key, value in quantities.items %}
      {% if key == product.id|slugify %}
      {{ value }}
      {% endif %}
      {% endfor %}
      1
      2
      3
      4
      5


      @@Codemycom

    • @viktorbonilla5509
      @viktorbonilla5509 11 หลายเดือนก่อน

      I think the problem is in my html, because the session id update the quantity, but i can find it.. @@Codemycom

  • @kevincranfield2471
    @kevincranfield2471 3 หลายเดือนก่อน

    Hi help please I have copied every code from your git hub page: I am receiving a sever internal error (500) at this address 127.0.0.1:8000/cart/update/
    When I try to press the update button
    // Update Cart
    $(document).on('click', '.update-cart', function(e){
    e.preventDefault();
    // grab the product id
    var productid = $(this).data('index');
    $.ajax({
    type: 'POST',
    url: '{% url 'cart_update' %}',
    data: {
    product_id: $(this).data('index'),
    product_qty: $('#select' + productid + ' option:selected').text(),
    csrfmiddlewaretoken: '{{ csrf_token }}',
    action: 'post'
    },
    success: function(json){
    //console.log(json)
    //document.getElementById("cart_quantity").textContent = json.qty
    location.reload();
    },
    error: function(xhr, errmsg, err){
    }
    });
    })

    • @Codemycom
      @Codemycom  3 หลายเดือนก่อน

      I never recommend copying and pasting code. Follow the video and write it out yourself.

    • @kevincranfield2471
      @kevincranfield2471 3 หลายเดือนก่อน

      @@CodemycomI’m determined to get it to work. I did type it all including the space but still got the error, copy pasting was a desperate move 😢. I will delete and retype

  • @MikeLegg-sy2ng
    @MikeLegg-sy2ng 6 หลายเดือนก่อน

    TypeError at /cart/update/
    int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

    • @Codemycom
      @Codemycom  6 หลายเดือนก่อน

      What did you do differently from the video?

  • @aljay7503
    @aljay7503 11 หลายเดือนก่อน

    Update button doesn't work...
    I've tried to change int for str and vice versa...
    I also went for the video many times and I get the same error:
    product_id = int(request.POST.get('product_id'))
    TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'
    "POST /cart/update/ HTTP/1.1" 500 64883

    • @Codemycom
      @Codemycom  11 หลายเดือนก่อน +1

      There's likely a problem with your javascript code on the cart-summary.html page or the button HTML code itself.

    • @Codemycom
      @Codemycom  11 หลายเดือนก่อน +4

      There must be s space befor option:selected -> '#select' + productid + ' option:selected' in /cart_summary.html

    • @collinswanyeki
      @collinswanyeki 11 หลายเดือนก่อน +1

      @@Codemycom Wow, this pre-saved me a few hours of troubleshooting. I was getting the error
      ValueError: invalid literal for int() with base 10: ''
      But the space before ' option:selected' helped a bunch

    • @aljay7503
      @aljay7503 11 หลายเดือนก่อน +1

      @@Codemycom Typo... There was a typo in my button HTML code:
      I typed date-index instead of data-index.
      Thanks

    • @namdarcs
      @namdarcs 11 หลายเดือนก่อน +1

      I made a few mistakes in spelling quantity as quanitity between cart.py and view.py first time around. The console/terminal gives you clues :)

  • @gpython1u
    @gpython1u 5 หลายเดือนก่อน

    File "C:\Users\wwwak\OneDrive\Desktop\ecom\ecom\cart\views.py", line 46, in cart_update
    product_qty=int(request.POST.get('product_qty'))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ValueError: invalid literal for int() with base 10: ' '
    plx provide valuable solution

    • @Codemycom
      @Codemycom  5 หลายเดือนก่อน

      You have an error in your code...the comment section will show your solution.

  • @romanbuchta248
    @romanbuchta248 11 หลายเดือนก่อน +1

    product_qty = int(request.POST.get('product_qty'))
    ValueError: invalid literal for int() with base 10: ''
    Same error here like a user has written befor ..

    • @Codemycom
      @Codemycom  11 หลายเดือนก่อน +1

      Same answer then :-p

    • @romanbuchta248
      @romanbuchta248 11 หลายเดือนก่อน +4

      @@Codemycom I have found the solution! There must be s space befor option:selected -> '#select' + productid + ' option:selected' in /cart_summary.html. It was easy for making this type-error.
      See you next week!!

  • @andreivrincean6967
    @andreivrincean6967 11 หลายเดือนก่อน

    product_qty = int(request.POST.get('product_qty'))
    ValueError: invalid literal for int() with base 10: ' '
    The same error. I checked everything. I applied what was written in the comments and still this same error. And git doesn't work for now.... As I see I get the qte to be an empty string or a space. Some hints maybe?

    • @Codemycom
      @Codemycom  11 หลายเดือนก่อน +2

      you missed a space in the ajax. There must be s space befor option:selected -> '#select' + productid + ' option:selected' in /cart_summary.html

    • @andreivrincean6967
      @andreivrincean6967 11 หลายเดือนก่อน

      @@Codemycom I checked the spelling and the space is there. I had previously an error in the java script code where it did not want to access the url and i needed to make a variable with the url and call it in the ajax function. Now, in the cart.py file we have the cart add function where we cat from our cart the id and qte. I discovered that the syntax product_id = str(product.id) was something wrong. I deleted the .id from the syntax and at first glance it works. The code was the same as in your tutorial and double checked with github repo. Maybe i have something wrong or misspelled somewhere else... I modified the qte several times, i checked the page and it gets correct the product id. I wil dig more in to it to see if i made something wrong on the way. Thanks. By the way great tutorial sir.

    • @AKHILjoseph01
      @AKHILjoseph01 9 หลายเดือนก่อน

      @@Codemycom but it doesn’t working ether, i put a space and checked my code several times

    • @AKHILjoseph01
      @AKHILjoseph01 9 หลายเดือนก่อน

      The inspect/console says - Failed to load resource: the server responded with a status of 500(internal server error )😢

    • @kevincranfield2471
      @kevincranfield2471 3 หลายเดือนก่อน

      @@AKHILjoseph01 I have the same did you get it fixed??

  • @federicocampo557
    @federicocampo557 11 หลายเดือนก่อน +1

    def cart_upd(request):
    cart = Cart(request)
    if request.POST.get('action') == 'post':
    product_id = int(request.POST.get('product_id'))
    product_qty = int(request.POST.get('product_qty'))
    cart.update(product=product_id, quantity=product_qty)
    response = JsonResponse({'qty':product_qty})
    return response
    line 30, in cart_upd
    product_qty = int(request.POST.get('product_qty'))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ValueError: invalid literal for int() with base 10: ''
    Any idea what could be the problem? I've watched the video three times, and I believe I've copied everything correctly

    • @Codemycom
      @Codemycom  11 หลายเดือนก่อน +1

      Probably an error on your cart_summary.html page. The product_qty you are passing can't be turned into an int.
      There must be s space before option:selected -> '#select' + productid + ' option:selected' in /cart_summary.html

    • @federicocampo557
      @federicocampo557 11 หลายเดือนก่อน

      @@Codemycom

      {% for key, value in quantities.items %}
      {% if key == product.id|slugify %}
      {{ value }}
      {% endif %}
      {% endfor %}
      1
      2
      3
      4
      5



      update




      {% endfor %}
      {% else %}

      No hay productos agregados...

      {% endif %}
      $(document).on('click', '.update-cart', function(e){
      e.preventDefault();
      var productid = $(this).data('index');
      $.ajax({
      type: 'POST',
      url: "{% url 'cart_update' %}",
      data: {
      product_id: $(this).data('index'),
      product_qty: $('#select' + productid + 'option:selected').text(),
      csrfmiddlewaretoken: '{{ csrf_token }}',
      action: 'post'
      },
      success: function(json){
      location.reload();
      },
      error: function(xhr, errmsg, err){
      }
      });
      })
      {% endblock %}
      Literal, I copied everything exactly as it is.
      This fix the problem
      var productid = $(this).data('index');
      //fix
      var qty = $('#select' + productid + ' option:selected').text();
      $.ajax({
      type: 'POST',
      url: "{% url 'cart_update' %}",
      data: {
      product_id: $(this).data('index'),
      product_qty: qty,
      csrfmiddlewaretoken: '{{ csrf_token }}',
      action: 'post'
      },
      Can you explain to me why the other code isn't working?

    • @romanbuchta248
      @romanbuchta248 11 หลายเดือนก่อน +1

      Same error here .....

    • @romanbuchta248
      @romanbuchta248 11 หลายเดือนก่อน +1

      I have found the solution! There must be s space befor option:selected -> '#select' + productid + ' option:selected' in /cart_summary.html

    • @Codemycom
      @Codemycom  11 หลายเดือนก่อน +1

      @@romanbuchta248 ah yeah, correcto!