I am having trouble with creating products for a commerce project with multiple sellers (each with their own store). The products these sellers are selling is a baseball card.
When a user adds a new product to sell, in the form submission I create the form as:
// create price...
$price = new Price($vals['price']['number'], $vals['price']['currency_code']);
// init variation
$variation_vals = [
'type' => 'card_type_baseball',
'status' => 1,
'sku' => 'baseball-1',
'price' => $price,
'field_card_image' => [$vals['image_fid']]
];
$variant = ProductVariation::create($variation_vals);
$variant->save();
// init product
$product_vals = [
'uid' => $this->getUID(),
'title' => $vals['name'],
'type' => 'card',
'stores' => [$this->store],
'variations' => [$variant],
];
$product = Product::create($product_vals);
$product->save();
It works, however, when I view the product after creation, I have many copies of image and field values for some reason.
I think I'm missing a concept.
When a user wants to sell their product, and they upload the product image, set the price, and enter the title for that card (through the form I provide via the Form API) I want to create the product that I can display in a view for the front page, or under their store on their store pages (which I can display via Views).
Every card has the same properties: an image, title, and a price. Examples,
1 - Barry Bonds, $20.00 (with img) 2 - Mark McGuire, $15.00 (with img)
Am I missing something in relation to creating products?