0

i have a custom module for shipping methods in magento 2

i need to get config product id in the cart list using jquery

Date-block.html

<script type="text/javascript">
require(
    ['jquery','jquery/ui'],
    //function($) {
      $(document).ready( function() {
        //alert(1);
        // read checkoutconfig
        var quoteData = checkoutConfig.quoteItemData,
          quote_length = quoteData.length,
          prep_times = [],
          creation_dates = [],
          cake_names = [],
          item_ids = [];

        // Manually prepare this list either by cake name or by item id


        var cakes_prep_time_by_name = {
'1101':'4',}
for(var i = 0; i < quote_length; i++) {
           // quoteData[i].name
           //var prep_time = quoteData[i].prep_time; //assumed
           //prep_times.push(prep_time);

           var order_time = quoteData[i].created_at;
           creation_dates.push(order_time);

           var cake_name = quoteData[i].name;
           cake_names.push(cake_name);

           var item_id = quoteData[i].item_id;
           item_ids.push(item_id);

           var prep_time = cakes_prep_time_by_name[cake_name];
           console.log(cake_name+'/'+prep_time);
           prep_times.push(prep_time);
</script>

when i go to check out i need to get all configurable products ids and new custom attribute

any one have idea???

3
  • share your code where you want this config mean configurable product id ? Apr 2, 2019 at 10:51
  • Added code........................ Apr 2, 2019 at 10:56
  • I would suggest to use window.checkoutConfig functionality. I am not sure what you exactly wanted by you may refer this link. magestore.com/magento-2-tutorial/…
    – Yash Shah
    Apr 2, 2019 at 11:21

2 Answers 2

0

You can use.

alert(quoteData[i].product_id);

I hope it's helpful for you.

2
  • how i can get custom product attribute value in magento 2 Apr 6, 2019 at 8:14
  • Can you please give me your url ? Apr 6, 2019 at 8:16
0

I needed this for a tamper monkey script, and feel this might help you compile what you need or extend the logic, to get the product id from a given shopping cart item within the checkout using jQuery and knockout in tandem.

// Load the contexts when needed
let jQuery = require('jquery');
let ko = require('knockout');

// use jQuery to get all the items in the shopping cart. 
// Change the selector if your checkout plugin uses different stylings.
jQuery('.checkout-product__name-qty').each((i,e) => 
{
    // Get the knockout context for the given checkout element.
    let context = ko.contextFor(e);

    // The actual quote item data is in the parent of the selected element that I chose to target.
    let quote_item_id = ko.contextFor(e).$parent.item_id;

    // Get the checkoutConfig quote item data
    let quote_data = window.checkoutConfig.quoteItemData;

    // Filter out our quote item
    let quote_item = quote_data.filter((item) => {return parseInt(item.item_id) === quote_item_id}).pop();
    
    // get the product ID from the quote item.
    let product_id = quote_item.product.entity_id;
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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