private ShopifyMetafieldMapping(int sourceId, DateTime creationDate, ShopifyMetafield thisField) { SourceId = sourceId; DestinationId = Convert.ToInt32(thisField.Value); SourceDate = creationDate; DestinationDate = creationDate; metafield = thisField; }
public static ShopifyMetafieldMapping CreateMetafieldMapping(int sourceId, DateTime creationDate, ShopifyMetafield thisField) { if (thisField.ValueType != "integer" || thisField.Namespace != "Shopsterify" || thisField.Key != "ShopsterProductId") { //ToDo: Throw exception? return null; //caller is responsible to check if creation worked. } return new ShopifyMetafieldMapping(sourceId, creationDate, thisField); }
private ConnectsterController() { _database = new ConnectsterDatabase(); _shopsterComm = ShopsterCommunicator.Instance(); _shopifyComm = ShopifyCommunicator.Instance(); //Todo: Change these namespaces, keys, valuetype into a config file entry. _metaFieldShopsterProductId = new ShopifyMetafield { Namespace = "Connectster", Key = "ShopsterProductId", ValueType = "integer" }; }
public ShopifyResponse<ShopifyMetafield> CreateMetafield(ShopifyStoreAuth storeAuth, ShopifyMetafield metaField, int? productId) { if (storeAuth == null || metaField == null) { Logger.WarnFormat("ShopifyCommunicator::CreateMetafield():storeAuth and metaField cannot be null"); return null; } if (productId != null && productId < 1) //Product ID can be null if the metafield is tagged to the store itself (vs. tagged to a product). { Logger.ErrorFormat("ShopifyCommunicator::CreateMetafield(): productId must be >=1 if non-null."); return null; } //Build our url depending on if this metafield will apply to e product or e shop var url = new StringBuilder(); url.Append(_protocol + storeAuth.StoreSubDomain + _domain + "/admin/"); if (productId != null) { url.Append("products/" + productId + "/"); } url.Append("metafields.xml"); var xS = new XmlSerializer(typeof (ShopifyMetafield)); var memStream = new MemoryStream(); var xDoc = new XmlDocument(); xS.Serialize(memStream, metaField); memStream.Seek(0, SeekOrigin.Begin); xDoc.Load(memStream); memStream.Close(); return new ShopifyResponse<ShopifyMetafield>(ShopifyPutPost(url.ToString(), HashString(_appAuth.Secret + storeAuth.StoreAuthToken), xDoc, "POST")); }