2017-12-12 9 views
0

Magento 시스템에서 Zapier로 배열을 가져 왔는데, 우리가 직면하는 유일한 문제는 이러한 데이터를 행에 자동 삽입하는 방법입니다.Magento 2 - 행을 자동으로 삽입하는 문제

여기서 데이터의 스크린 샷이다 : http://prntscr.com/hmbocu

난의 foreach를 사용하여 어레이를 제어하는 ​​JS를 사용해야 든 생각 만하면,이 Zapier를 사용 가능하다. 이와 관련하여 힌트를 기대합니다.

아래 코드는 통제해야하는 항목의 행입니다.

<tbody> 
<tr> 
<td class="item-info has-extra" style="font-family: &quot;Poppins&quot;, sans-serif, 'Helvetica Neue', Helvetica, Arial, sans-serif; vertical-align: top; padding: 10px; border-top: 1px solid #eaeaea;"> 
     <p class="product-name" style="margin-top: 0; margin-bottom: 5px; font-weight: 700;">{{27698666__items[]name}}</p> 
     <p class="sku" style="margin-top: 0; margin-bottom: 10px;">{{27698666__items[]parent_item__sku}}</p> 
</td> 
    <td class="item-qty" style="font-family: &quot;Poppins&quot;, sans-serif, 'Helvetica Neue', Helvetica, Arial, sans-serif; vertical-align: top; padding: 10px; border-top: 1px solid #eaeaea; text-align: center;">{{qty}}</td> 
    <td class="item-price" style="font-family: &quot;Poppins&quot;, sans-serif, 'Helvetica Neue', Helvetica, Arial, sans-serif; vertical-align: top; padding: 10px; border-top: 1px solid #eaeaea; text-align: right;"> 
     <span class="price">{{27698666__items[]parent_item__price_incl_tax}}</span> 
    </td> 
</tr> 
</tbody> 

답변

0

내가 먼저, 즉 (이름, 가격, SKU 수량), 다음 거기에서, 당신은을 줄여 봐 할 수 있어야한다 당신이 행마다 삽입 할 변수를 명시해야 필요가 해결책을 발견했다 변수를 정의하고 배열을 단수로 분리하여 스크립트를 따르십시오.

이 정보는 도움이되기를 바랍니다.

var qty = inputData.qty.split(","); 
var name = inputData.name.split('"'); 
var sku = inputData.sku.split(","); 
var price = inputData.price.split(","); 
for (var i=0;i<qty.length;i++) { 
    if (i==0) var data = "<tr><td class=\"item-info has-extra\" style=\"font-family: &quot;Poppins&quot;, sans-serif, 'Helvetica Neue', Helvetica, Arial, sans-serif; vertical-align: top; padding: 10px; border-top: 1px solid #eaeaea;\"><p class=\"product-name\" style=\"margin-top: 0; margin-bottom: 5px; font-weight: 700;\">" + name[i] + "</p><p class=\"sku\" style=\"margin-top: 0; margin-bottom: 10px;\">" + sku[i] + "</p></td><td class=\"item-qty\" style=\"font-family: &quot;Poppins&quot;, sans-serif, 'Helvetica Neue', Helvetica, Arial, sans-serif; vertical-align: top; padding: 10px; border-top: 1px solid #eaeaea; text-align: center;\">" + qty[i] + "</td><td class=\"item-price\" style=\"font-family: &quot;Poppins&quot;, sans-serif, 'Helvetica Neue', Helvetica, Arial, sans-serif; vertical-align: top; padding: 10px; border-top: 1px solid #eaeaea; text-align: right;\"><span class=\"price\">" + price[i] + "</span></td></tr>"; 
    else data = data + "<tr><td class=\"item-info has-extra\" style=\"font-family: &quot;Poppins&quot;, sans-serif, 'Helvetica Neue', Helvetica, Arial, sans-serif; vertical-align: top; padding: 10px; border-top: 1px solid #eaeaea;\"><p class=\"product-name\" style=\"margin-top: 0; margin-bottom: 5px; font-weight: 700;\">" + name[i] + "</p><p class=\"sku\" style=\"margin-top: 0; margin-bottom: 10px;\">" + sku[0] + "</p></td><td class=\"item-qty\" style=\"font-family: &quot;Poppins&quot;, sans-serif, 'Helvetica Neue', Helvetica, Arial, sans-serif; vertical-align: top; padding: 10px; border-top: 1px solid #eaeaea; text-align: center;\">" + qty[i] + "</td><td class=\"item-price\" style=\"font-family: &quot;Poppins&quot;, sans-serif, 'Helvetica Neue', Helvetica, Arial, sans-serif; vertical-align: top; padding: 10px; border-top: 1px solid #eaeaea; text-align: right;\"><span class=\"price\">" + price[0] + "</span></td></tr>"; 
} 
output = {data}