Closed hexfusion closed 9 years ago
Two concerns:
I agree with control what if you can have the "option" of setting attributes lazy. So if you want to set attributes in this manner it is up to you to validate them before entry. Could even call this lazy_attributes with this caveat.
But with gtin a canonical product should never have one as the canonical product is not actually a product only a container for product variants. So in this case you have $product and are adding only variants which should either have unique gtin or undef. Also the attributes that are being used in this method are that of that actual variant so it shouldn't conflict.
You need a way to add the GTINs per variant, so it is no longer so clean as your example above.
I see ... but in this case it should be find_or_create_variant.
yes
Which SKU is that? The canonical?
sku of variant the $product object has canonical_sku so full workflow would be.
my $product = shop_product->find({ sku => 'WBA-WY'});
$product->find_or_create_variant(
{
lazy_attributes => [
{
name => "color",
title => "Color",
value => "sage",
value_title => "Sage"
},
{
name => "size",
title => "Size",
value => "L",
values_title => "Large"
}
],
sku => "WBA-WY-CY07",
gtin => "690000000000",
name => "Kids Gore-Tex\x{ae} Stockingfoot Sage Large",
price => "199.95",
}
);
for this to be effective it would require defining priority for the attribute value as well. I guess the usecase for this would be limited to a small group of instances and could be created locally. I'm going to close this pending testing of this method in Angler::Populate.
Currently the process of creating attributes is separate from adding a product variant. I propose the following helper method.
find_or_create_variants where your attributes list is an array of hashes like this
From here we can find_or_create both attributes and product variants. Eliminating a full population step that uses the same data.