我想直接使用購(gòu)物車中的Shopify訂單項(xiàng)屬性進(jìn)行編輯/保存,/cart/change.js而不必回到產(chǎn)品頁(yè)面重新輸入信息。訂單項(xiàng)屬性由名稱/值組成。每個(gè)購(gòu)物車項(xiàng)目最多具有3個(gè)訂單項(xiàng)屬性名稱(“場(chǎng)合”,“其他注釋”,“封閉卡”),它們各自的對(duì)應(yīng)值是唯一的。我似乎無(wú)法使它與多個(gè)購(gòu)物車商品或多個(gè)屬性名稱/值一起使用。由于每個(gè)屬性值ID都是屬性值本身,因此我嘗試為每個(gè)值創(chuàng)建動(dòng)態(tài)ID,以便可以唯一地定位每個(gè)購(gòu)物車商品屬性并覆蓋現(xiàn)有值。但是,我似乎無(wú)法弄清楚該如何做。出于示例目的,為了進(jìn)行編輯,property-name我想執(zhí)行以下操作:$('.cart-line-item-update').on('click', function() { const $this = $(this); const dataIndex = $this.data('index'); const item = cart_items[dataIndex - 1]; item.properties['property-name'] = $('#dynamic-property-value').val(); jQuery.ajax({ url: '/cart/change.js', dataType: 'json', data: { line: dataIndex, properties: item.properties } }).done(function() { window.location.reload() })});<script> var cart_items = {{cart.items | json}} </script>{% if property_size > 0 %} {% assign loop_index = forloop.index %} {% for p in item.properties %} {% assign first_character_in_key = p.first | truncate: 1, '' %} {% unless p.last == blank or first_character_in_key == '_' %} <div class="accordion-container collapse-all cart-line-item-accordion"> <input type="checkbox" title="Expand for more information" checked> <h2 class="accordion-title"> <span id="{{ item.product_id }}-{{ p.first | handleize }}">{{ p.first }}:</span> <i class="accordion-icon"></i> </h2> <div class="accordion-content"> <div class="saved-textarea visible"> {{ p.last }} </div> <textarea id="{{ item.product_id }}-{{ p.first | handleize }}-textarea" class="update-textarea autosize new-property">{{ p.last }}</textarea>預(yù)期的結(jié)果:每個(gè)購(gòu)物車商品屬性值將被保存(覆蓋現(xiàn)有的json值)。實(shí)際結(jié)果:只會(huì)更新第一個(gè)購(gòu)物車商品屬性值并保存。如果購(gòu)物車中有多個(gè)項(xiàng)目,每個(gè)項(xiàng)目都有自己的值,它將不會(huì)保存該屬性的后續(xù)實(shí)例,而將第一個(gè)實(shí)例覆蓋它們。這些值已經(jīng)存在于json中,因?yàn)樗鼈兪窃诋a(chǎn)品頁(yè)面上創(chuàng)建并轉(zhuǎn)移到購(gòu)物車的。我只是不知道如何針對(duì)每個(gè)舊的json值以新的值覆蓋它。該腳本似乎將屬性名的所有實(shí)例作為目標(biāo),并用第一個(gè)值覆蓋所有實(shí)例。也許我缺少明顯的東西。誰(shuí)能幫忙嗎?
直接在購(gòu)物車中編輯和保存Shopify訂單項(xiàng)屬性
BIG陽(yáng)
2021-05-14 14:12:52