XiaoFaye / WooCommerce.NET

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

Woocommerce WPML translations field #708

Closed FabPari closed 1 year ago

FabPari commented 1 year ago

Hi Dear with wcommerce and WPML on REST api product request you have also variable named "translations" containing list id of products translated. Possible for you to implement this on the product object? Thanks Fabio image

XiaoFaye commented 1 year ago

I think you can create a new object with new fields which inherits the product object

FabPari commented 1 year ago

Hi dear, tnks to much. Have you an example to show me? Tnks Fabio

Il ven 14 ott 2022, 05:00 James Yang @.***> ha scritto:

I think you can create a new object with new fields which inherits the product object

— Reply to this email directly, view it on GitHub https://github.com/XiaoFaye/WooCommerce.NET/issues/708#issuecomment-1278407486, or unsubscribe https://github.com/notifications/unsubscribe-auth/AP4MNMLYV6QU3YE427ORNXDWDDEERANCNFSM6AAAAAARENKMGY . You are receiving this because you authored the thread.Message ID: @.***>

FabPari commented 1 year ago

I found a solution, and I hope can help some one.

Product object extension:

namespace WoocommerceExtendedClient
{
    [DataContract]
    public class ProductExtended : WooCommerceNET.WooCommerce.v3.Product
    {
        public static string Endpoint { get { return "products"; } }
        [DataMember]
        public Translations translations { get; set; }
    }
}

namespace WoocommerceExtendedClient.WooCommerce
{
    class WCObjectExtended : WCObject<Coupon, Customer, ProductExtended, ProductReview, Variation, Order, OrderNote, OrderRefund, ProductAttribute, ProductAttributeTerm,
                                    ProductCategory, ShippingClass, ProductTag, TaxRate, TaxClass, Data>
    {
        public WCObjectExtended(RestAPI api) : base(api)
        {
        }
    }
}

Declaration and usage

WoocommerceExtendedClient.WooCommerce.WCObjectExtended wc = new WoocommerceExtendedClient.WooCommerce.WCObjectExtended(rest);

var products = new List<WoocommerceExtendedClient.ProductExtended>();
            Dictionary<string, string> pDic = new Dictionary<string, string>();
            pDic.Add("sku", SKU);
            pDic.Add("lang", "it");
 products = wc.Product.GetAll(pDic).Result;

thanks for support Fabio