XiaoFaye / WooCommerce.NET

A .NET Wrapper for WooCommerce/WordPress REST API
MIT License
393 stars 218 forks source link

ProductTag vs ProductTagLine #497

Closed MKI-Miro closed 1 year ago

MKI-Miro commented 4 years ago

Make sure you have included the below details when open an issue. Thank you.

Hi

From WCObject I am only able to retrieve ProductTag object.

I want to add product tag to Product object. ProductTag object has property tags which is type of ProductTagLine.

How I am supposed to do it?

`var wc = new WCObject(rest); var items = wc.Tag.GetAll(); // Items of type productTags

product.tags.Add(items.FirstOrDefault(p => p.name == productInDb.Manufacturer.Name)); `

Error CS1503 Argument 1: cannot convert from 'WooCommerceNET.WooCommerce.v3.ProductTag' to 'WooCommerceNET.WooCommerce.v3.ProductTagLine'

Thanks

XiaoFaye commented 4 years ago

When adding product tag, you should use ProductTag object.

MKI-Miro commented 4 years ago

But I want to link existing product with existing tag. But from wcobject I am only able to retrieve productTag and product object has only list of productTagLines

XiaoFaye commented 4 years ago

In this case, product.Update should be used, not product.tags.Add.

MKI-Miro commented 4 years ago

But again input for product update is Product object and this object has property tags which is type of ProductTagLine so i am not able to assign ProductTag Object

`var wc = new WCObject(rest);

var updatedProduct = wc.Product.Update(productId, product)`

XiaoFaye commented 4 years ago

ProductTag is for making changes to product tag ONLY, if you are updating product, please use ProductTagLine.

MKI-Miro commented 4 years ago

Thank you but I am still confused. Can you please provide small example how to connect exsiting product with exsitin tag?

ZOLBYTE commented 4 years ago

@XiaoFaye great work. Thank you! I've the same issue & confusion as @MKI-Miro

MKI-Miro commented 4 years ago

Can someone help? This is not working

`// All slate manufacturers var slateTags = _slateProductTagRepository.GetAllTags(domain, wooKey, wooSecret);

var productTag = slateTags.FirstOrDefault(p => p.name == productInDb.Manufacturer.Name);

if (productTag != null) { productInSlate.tags.Add(productTag); // ERROR Cannot convert ProductTag to ProductTagLine }`