2017-10-16 1 views
1

Buy 버튼을 사용하여 쇼핑을 위해 meteor js 웹 사이트를 연결하는 최선의 방법이 확실하지 않습니다. http://shopify.github.io/js-buy-sdk/ - - 는 Shopify의 API를 initializie에 직접, 나는이 예제가있다 package.jsonmeteor js 웹 사이트에 shopify 구매 버튼을 추가하십시오.

}, 
    "dependencies": { 
    "babel-runtime": "^6.26.0", 
    "bcrypt": "^1.0.3", 
    "shopify-buy": "^0.7.1", 
    "shopify-promise": "0.0.5", 
    "simpl-schema": "^0.3.2" 
    }, 

에 표시

meteor npm install --save shopify-buy 
meteor npm install --save shopify-promise 

이 패키지를 사용하여 shopify-구입하고 shopify-약속 NPM 패키지를 가져 http://shopify.github.io/js-buy-sdk/examples/

<em>After fetching a product with the product ID we use the promise function to generate some markup with the required attributes and content, and add it inside our HTML container element.</em> 

client.fetchProduct('your-product-id').then(function(product) { 

    var html = 
    "<img class='product__image' src='" + product.selectedVariantImage.src + "' >" + 
    "<h2 class='product__title'>" + product.title + "</h2>" + 
    "<a class='product__buy' href='" + 
    product.selectedVariant.checkoutUrl(1) + 
    "'>Buy Now!</a>"; 

    $('#product-1').html(html); 

}); 

하지만 데이터 만 다시 전달해야하기 때문에 나는 유성 JS 템플릿에 다시이 HTML을 전달하는 방법을 확실하지.

위와 비슷한 JS 코드를 사용하여 각 제품에 ShopifyBuyUrl 필드로 Shopify 단추 URL을 추가하려고했습니다. 내가 서버에서이 작업을 수행/

Meteor.startup(function() { 
     var shopifyBuyUrl = require('shopify-buy'); 

     const shopClient = shopifyBuyUrl.buildClient({ 
      api_key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 
      accessToken: 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy', 
      domain: 'test1.myshopify.com', 
      appId: '6' 
    }); 
    [ ... then I have code here that loads the product categories array - this array has 6 categories and an array of products within each category ...] 
    [next I try and pre-fill the shopifyBuyUrl value for each product] 

    for (var i=0; i < 6; i++) { 
      // fetch a product using resource id 
      for (var j=0; j < products[i].length; j++) { 
       // shopify product id is hardcoded for now 
       products[i][j].shopifyProductId='12836712587'; 

       shopClient.fetchProduct('12836712587').then(function(product) { 

       products[i][j].shopifyBuyUrl=product.selectedVariant.checkoutUrl(1); 
       }) 
        .catch(function() { 
          console.log('Request failed'); 
        }); 
       } 
      }  

     console.log('Inserting categories into MongoDB ...'); 
     for (var i=0; i < 6; i++) { 
      Categories.insert(
       { 
        img_alt:name[i], 
        img_src:src[i], 
        desc:desc[i], 
        products:products[i], 
       }); 
     } 
} 

을 startup.js 위의 코드는 Shopify 성공적으로 인증하고 shopClient 인스턴스를 생성 할 수 있습니다. Shopify Buy URL을 생성하라는 shopify 호출은 가끔 성공하며 때로는 '요청 실패' 메시지의 로깅에 실패합니다. 오류가 동일한 제품 ID를 반복적으로 사용하는 것과 관련이 있는지 확실하지 않습니다!

위와 같이 Shopify API를 직접 사용할지 유성 가게 사용 패키지인지 여부가 확실하지 않으므로 https://github.com/froatsnook/meteor-shopify 패키지를 프로젝트에 추가 했으므로 인증이이 패키지에 적용되었습니다. 그러나이 패키지를 사용하여 Shopify Buy를 사용하는 방법은 패키지 API/데모에서 분명하지 않습니다.

전반적으로 나에게 명확하지 않은 점은 Shopify를 Meteor JS와 함께 사용하는 것이 가장 좋고 올바른 접근 방법입니다. froatsnook가는 길입니까, 더 이상 적용 할 수 없습니까? 이상적으로는 Shopify에 직접가는 것이 가장 좋지만 유성과 어떻게 작동하는지 확실하지 않은 것 같습니다.

Shopify Buy Button을 Meteor JS 프로젝트에 추가하는 데 도움이 될만한 것이 있으면 감사하겠습니다.

답변

0

수정 같은

사용 그것은이 링크 https://help.shopify.com/manual/sell-online/buy-button/create-buy-button을 기반으로합니다. 코드는 페이지 본문에 포함됩니다. shopify prod id 및 shopify prod 구성 요소에 대한 변수를 각 제품의 소스 데이터에 저장합니다. 유료화 된 제품 데이터의 전부 또는 일부를 가져 오거나 유성 웹 사이트에 저장된 MongoDB의 데이터를 사용할 수 있습니다.

products[i][j].shopifyBuyUrl=product.selectedVariant.checkoutUrl(1);을 호출 한 결과로 구입 버튼 URL을 작성한 것에 따라 처음 시도한 방식이 효과가 있는지는 확실하지 않습니다.

1

라이브러리를 사용하기 전에 정말로 필요합니까? 이 같은

뭔가 수행해야합니다

var ShopifyBuy = require('shopify-buy'); 

너무 적은 정보로 확실히 무슨 일이 일어나고 있는지 말하기 어렵다.

편집 :이

const shopClient = ShopifyBuy.buildClient({ 
    accessToken: 'bf081e860bc9dc1ce0654fdfbc20892d', 
    appId: 6, 
    domain: 'embeds.myshopify.com' 
}); 
+0

var를 추가했지만'W20171016-21 : 19 : 23 '이 붙습니다.685 (1)? (STDERR) 오류 : 새로운 Config()에 'accessToken'옵션이 필요합니다. Q를 좀더 자세하게 업데이트하여 잘 보일 수 있도록했습니다. – striker77

+0

'var'을 'const'로 변경하고 액세스 토큰을 추가했습니다. 고마워. 이제는 제품 주문 양식에 구매 버튼을 추가해야합니다. server/startup.js에 배열을 만들 때 제품 배열에 'Buy Button'URL을 추가하는 것을 생각합니다. 비록 '1'이 여기서 무엇을 의미하는지 명확하지 않다. 'product.selectedVariant.checkoutUrl (1)' – striker77

+0

@ striker77 var에 대한 var는 작동 여부에 영향을 미치지 않습니다. 'product.selectedVariant.checkoutUrl (1)'로 무엇을 의미하는지 모르겠습니다. 도움이된다면 올바른 답을 선택하는 것을 잊지 마세요! :) – bezzoon

관련 문제