public static void UnitTest() { CurrentContainer = new IoCContainer(); IO.Container = CurrentContainer; SettingsService.InclVat(); VatCalculationStrategy.OverParts(); Logger.Mock(); UwebshopConfiguration.UseType <UwebshopConfiguration>(); // todo no UseType? (slow) UwebshopRequestService.Use(MockConstructors.CreateMockUwebshopRequestService()); OrderDiscountRepository.SetupFake(); CategoryService.Use(MockConstructors.CreateMockEntityService <ICategoryService, Category>()); ProductVariantService.Use(MockConstructors.CreateMockEntityService <IProductVariantService, ProductVariant>()); CouponCodeService.Mock(); StoreRepository.Use(new TestStoreRepository()); CMSEntityRepository.Use(new TestCMSEntityRepository()); CountryRepository.Use(new TestCountryRepository()); VATCountryRepository.Use(new TestVATCountryRepository()); OrderRepository.Mock(); ProductDiscountRepository.Mock(); ProductRepository.Mock(); ProductVariantGroupRepository.Mock(); CategoryRepository.Mock(); ProductVariantRepository.Mock(); CMSApplication.Use(new StubCMSApplicationNotInBackend()); HttpContextWrapper.Mock(); DiscountService.UseType <FakeDiscountService>(); StoreService.Use(new TestStoreService()); OrderService.Use(new TestOrderService()); ProductService.Use(new TestProductService()); CMSDocumentTypeService.Use(new StubCMSDocumentTypeService()); OrderUpdatingService.Mock(); OrderNumberService.Mock(); CatalogUrlResolvingService.Mock(); PaymentProviderService.Mock(); StoreFromUrlDeterminationService.Mock(); StockService.Mock(); ApplicationCacheService.Mock(); UwebshopRequestService.Use(new StubUwebshopRequestService()); CurrentContainer.SetDefaultServiceFactory(new MockServiceFactory()); ModuleFunctionality.Register(CurrentContainer); CurrentContainer.RegisterType <IContentTypeAliassesXmlService, StubContentTypeAliassesXmlService>(); CurrentContainer.RegisterType <IProductVariantGroupService, ProductVariantGroupService>(); InitializeServiceLocators(); }
public ProductVariantController(CartModel cart, IProductVariantUIService productVariantUIService, IProductReviewUIService productReviewUIService, ProductReviewSettings productReviewSettings, ProductVariantService productVariantService) { _cart = cart; _productVariantUIService = productVariantUIService; _productReviewUIService = productReviewUIService; _productReviewSettings = productReviewSettings; _productVariantService = productVariantService; }
public static void InitServices(string getProductAPIFile = null, string getVariantsAPIfile = null) { if (getProductAPIFile != null) { getProductService = ShopifyAPIConfig.MakeService <ProductService>(getProductAPIFile); } if (getVariantsAPIfile != null) { getVariantService = ShopifyAPIConfig.MakeService <ProductVariantService>(getVariantsAPIfile); } }
public static void InitServices(string updateInventoryAPIFile = null, string updateVariantAPIfile = null, string updateMetafieldsAPIFile = null) { if (updateInventoryAPIFile != null) { updateInventoryService = ShopifyAPIConfig.MakeService <InventoryLevelService>(updateInventoryAPIFile); } if (updateVariantAPIfile != null) { updateVariantService = ShopifyAPIConfig.MakeService <ProductVariantService>(updateVariantAPIfile); } if (updateMetafieldsAPIFile != null) { updateMetafieldService = ShopifyAPIConfig.MakeService <MetaFieldService>(updateMetafieldsAPIFile); } }
public async Task Post(Customer obj) { var shop = _context.Shopify.Single(b => b.StoreName == obj.StoreName); string Token = shop.Token; string store = shop.StoreName; var service = new ProductService(store, Token); var service1 = new CustomerService(store, Token); var service2 = new ProductVariantService(store, Token); var service3 = new ProductImageService(store, Token); var product = await service.GetAsync(long.Parse(obj.product_id)); var customer = await service1.GetAsync(long.Parse(obj.customer_id)); obj.customer_name = customer.FirstName; obj.customer_email = customer.Email; obj.product_title = product.Title; var variant = await service2.GetAsync(long.Parse(obj.variant_id)); obj.variant_sku = variant.SKU; obj.variant_barcode = variant.Barcode; // var image = await service3.GetAsync(long.Parse(obj.product_id), (long)variant.ImageId); IEnumerable <ProductImage> obj1 = product.Images; obj.variant_image = obj1.ElementAt(0).Src; _context.Add(obj); await _context.SaveChangesAsync(); }
public async Task <ShopifySharp.Product> CreateProduct(ImportService.Wrapper.Product product, string vendor, string myShopifyDomain, string accessToken, ImportService.Wrapper.ColorList colorMapping) { ShopifySharp.ProductService service = new ShopifySharp.ProductService(myShopifyDomain, accessToken); var newProduct = new ShopifySharp.Product() { Vendor = vendor, }; newProduct.Options = new List <ProductOption> { new ProductOption { Name = "Color" }, new ProductOption { Name = "Size" } }; string productTitle = product.Name; string productHandle = product.Name; var colorList = product.ProductVariants.ProductVariant.Select(x => new { colorName = x.ColorName, colorCode = x.ColorCode }).ToList(); var distColorList = colorList.Distinct().Select(x => x).ToList(); string colorName = colorList.Distinct().FirstOrDefault().colorName; if (!string.IsNullOrEmpty(colorName)) { colorName = CheckColorMapping(colorMapping, colorName); productHandle += "-" + colorName; productTitle += " " + colorName; } newProduct.Handle = productHandle.ToLower(); newProduct.Title = productTitle.ToUpper(); var productTags = new List <string>(); foreach (var c in distColorList) { string _color = CheckColorMapping(colorMapping, c.colorName); productTags.Add(product.Name.ToLower() + "-" + _color.ToLower()); } // product variant list created from ftp xml. var _pvList = new List <ShopifySharp.ProductVariant>(); var priceTagList = new List <string>(); foreach (var pv in product.ProductVariants.ProductVariant) { var _pv = new ShopifySharp.ProductVariant(); string variant_color = CheckColorMapping(colorMapping, pv.ColorName); _pv.SKU = product.Name.Replace(" ", "-").ToUpper(); _pv.Option1 = variant_color; _pv.Option2 = pv.SizeName; _pv.Option3 = pv.ColorCode; _pv.TaxCode = "PC040144"; _pv.Title = $@"{pv.ColorName.ToUpper()} /\ {pv.SizeName} /\ {variant_color}"; _pv.Price = Convert.ToDecimal(pv.ProductVariantSources.ProductVariantSource.Price); _pv.InventoryQuantity = Convert.ToInt32(pv.Quantity); _pvList.Add(_pv); if (_pv.Price < 25) { priceTagList.Add("PRICE_under_$25"); } else if (_pv.Price >= 25 && _pv.Price <= 50) { priceTagList.Add("PRICE_$25-$50"); } else if (_pv.Price >= 50 && _pv.Price <= 100) { priceTagList.Add("PRICE_$50-$100"); } else if (_pv.Price >= 100 && _pv.Price <= 150) { priceTagList.Add("PRICE_$100-$150"); } } var productVariants = _pvList.DistinctBy(x => x.Title).Select(x => x).ToList(); var exist = await GetProductByHandle(newProduct.Handle, service); if (exist.Count() > 0) { foreach (var p in exist) { var existingPV = p.Variants; var result = from x in productVariants join y in existingPV on new { X1 = x.Option1, X2 = x.Option2 } equals new { X1 = y.Option1, X2 = y.Option2 } select x; var newVariants = productVariants.Where(p1 => !result.Any(p2 => p2.Option1 == p1.Option1 && p2.Option2 == p1.Option2)); if (newVariants != null) { ShopifySharp.ProductVariantService pvs = new ProductVariantService(myShopifyDomain, accessToken); foreach (var nvp in newVariants) { var variant = await pvs.CreateAsync(p.Id ?? 0, nvp); } } } } else { newProduct.Variants = productVariants; foreach (var p in priceTagList.Distinct().Select(x => x).ToList()) { productTags.Add(p.ToLower()); } newProduct.Tags = string.Join(",", productTags.ToArray()); var createdDate = product.Attributes.Attribute.Where(x => x.ProductAttributeCode == "createddate").Select(x => x.ProductAttributeValue).FirstOrDefault(); if (createdDate != null) { newProduct.CreatedAt = Convert.ToDateTime(createdDate); } try { newProduct = await service.CreateAsync(newProduct); } catch (Exception ex) { string exception = ex.Message; if (ex.InnerException != null) { exception = ex.InnerException.Message; } Log.Error("Error in CreateProduct method in class ProductService.cs", ex, vendor); } } return(newProduct); }