Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variants should support unique MPN #33

Open
LetsPrint3D opened this issue Jul 1, 2018 · 3 comments
Open

Variants should support unique MPN #33

LetsPrint3D opened this issue Jul 1, 2018 · 3 comments

Comments

@LetsPrint3D
Copy link

According to the Google documentation, it says "Typically, each variant of a product (different colors or sizes) has its own MPN, so make sure to submit the correct value."

The function variant() in this library calls getGroupIdentifier() which requires an MPN (or GTIN) already be set before it can create the variant, meaning it is using the same one for all variants.

How can this be fixed?

@lukesnowden
Copy link
Owner

getGroupIdentifier() is just used for the group of products, you can still use $variant->mpn('blabla'); to set the variants mpn value.

@LetsPrint3D
Copy link
Author

LetsPrint3D commented Jul 3, 2018

Thanks for the feedback. What I am referring to is the exception MissingIdentifierException: Please define a GTIN or MPN value before creating a variant. which is thrown if I try to create the variant without setting the MPN first. I may just be overlooking something but this is what my code looks like...

foreach ($products as $product)
{
	$product_link = $store['domain'] . '/products/' . $product['handle'];
	$product_image = $product['image']['src'];

	$item = GoogleShopping::createItem();

	$item->id($product['id']);
	$item->title($product['title']);
	$item->description($product['body_html']);

	$item->link($product_link);
	$item->image_link($product_image);
	
	foreach ($product['variants'] as $variant)
	{
		$v = $item->variant();
		$v->mpn($variant->sku);
	}
}

@lukesnowden
Copy link
Owner

If you are creating variants, then just call the MPN anything, it is only used for the group identifier as the initial object should be destroyed;

foreach($products as $product)
{
	$product_link = $store['domain'] . '/products/' . $product['handle'];
	$product_image = $product['image']['src'];

	$item = GoogleShopping::createItem();

	$item->id($product['id']);
	$item->title($product['title']);
	$item->description($product['body_html']);

	$item->link($product_link);
	$item->image_link($product_image);
        $item->mpn(substr(0, 8, sha1($product['id'])));
	
	foreach ($product['variants'] as $variant)
	{
		$v = $item->variant();
		$v->mpn($variant->sku);
	}

        $item->delete();

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants