Shopify - 产品变体API

时间:2016-04-20 21:46:20

标签: shopify variant

有没有办法通过一次POST调用为单个产品创建多个产品变体?

我知道单个产品变体可以用:

POST /admin/products/#{id}/variants.json
{
   "variant": 
   {
      "option1": "Default Title",
      "price": "1.00"
    }
}

是否可以执行单个POST为同一产品ID创建多个变体?

1 个答案:

答案 0 :(得分:0)

是。以下是用于向现有产品添加新变体的节点示例。需要注意的是,您必须使用要保留的变体的ID填充变体数组:

    int const S=3; // number of attributes for each graph
    int const N=10;// number of vertex
    int const m=5;//number of edges
    int const SIZE=3;// number of graphs
    struct Attributes
     {

      int Attribute0[S];

    };

    struct EdgeAttributes
    {
      string name;
      double miles;
      int speed_limit;
      int lanes;
      bool divided;
    };

    typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS,
    Attributes, EdgeAttributes> Map;

    void outputgraph(Map&);
      Map * ggg= new Map[SIZE] ;
    int main()
    {
        Map map; // load the map
        bool inserted;

        Map::vertex_descriptor v ;

        for(int k=0; k<SIZE; k++)
        {
     for(int j=0; j<N; j++)
     {
         v= add_vertex(ggg[k]);
         for(int i=0; i<S; i++)
  { 

      ggg[k][v].Attribute0[i]=0 + (int)3 * rand() / (RAND_MAX + 1);


  }

     }
        }
         Map::edge_descriptor e;





         for(int k=0; k<SIZE; k++)
        {
         for(int i=0;i<m;i++)
      {
        tie(e,inserted) = add_edge(N * rand() / (RAND_MAX + 1), N * rand()     /     (RAND_MAX + 1), ggg[k]);
      }

         }


        std::cout << std::endl;

        outputgraph(map);
        int d;
        std::cin>>d;
    }

    struct my_node_writer {
        // my_node_writer() {}
        my_node_writer(Map& g_) : g (g_) {};
        template <class Vertex>
        void operator()(std::ostream& out, Vertex v) {
            out << "[";
             for(int i=0; i<S; i++)
                out <<"Attribute"<<i<<"="<<g[v].Attribute0[i]<<", ";
             out<<"]" << std::endl;
        };

        Map g;
    };

    struct my_edge_writer {
        my_edge_writer(Map& g_) : g (g_) {};
        template <class Edge>
        void operator()(std::ostream& out, Edge e) {
                // just an example, showing that local options override     global

                out << " [label=\"" << e  << "\"]" << std::endl;
        };
        Map g;
    };

    struct my_graph_writer {
        void operator()(std::ostream& out) const {

        }
    } myGraphWrite;

    void outputgraph(Map& map){
        std::ofstream gout;
        gout.open("graphname.dot");
        for(int i=0; i<S; i++)
        {
            write_graphviz(gout,ggg[i],my_node_writer(ggg[i]),my_edge_writer(ggg[i]),myGraphWrite);
        }
        // std::cout() << "done writing graph" << std::endl;
        gout.close();
    }