예제 #1
0
        public void PostStock(string productIdentifier, Stock stock)
        {
            ProductIdentifier productIdentifierObj = new ProductIdentifier(productIdentifier);

            IContent content = ApplicationContext.Current.Services.ContentService.GetById(productIdentifierObj.NodeId);
            IProductInformationExtractor <IContent, VariantPublishedContent> productInformationExtractor = ContentProductInformationExtractor.Instance;
            IVariantService <IContent, VariantPublishedContent> contentVariantService = ContentVariantService.Instance;

            long storeId = productInformationExtractor.GetStoreId(content);
            VariantPublishedContent variant = contentVariantService.GetVariant(storeId, content, productIdentifierObj.VariantId);

            stock.Sku = !string.IsNullOrEmpty(stock.Sku) ? stock.Sku : productInformationExtractor.GetSku(content, variant);

            ProductService.Instance.SetStock(storeId, stock.Sku, !string.IsNullOrEmpty(stock.Value) ? stock.Value.ParseToDecimal() : null);
        }
예제 #2
0
        public Stock GetStock(string productIdentifier)
        {
            Stock             stock = new Stock();
            ProductIdentifier productIdentifierObj = new ProductIdentifier(productIdentifier);

            IContent content = ApplicationContext.Current.Services.ContentService.GetById(productIdentifierObj.NodeId);
            IProductInformationExtractor <IContent, VariantPublishedContent> productInformationExtractor = ContentProductInformationExtractor.Instance;
            IVariantService <IContent, VariantPublishedContent> contentVariantService = ContentVariantService.Instance;

            long storeId = productInformationExtractor.GetStoreId(content);
            VariantPublishedContent variant = contentVariantService.GetVariant(storeId, content, productIdentifierObj.VariantId);

            stock.Sku = productInformationExtractor.GetSku(content, variant);
            decimal?stockValue = ProductService.Instance.GetStock(storeId, stock.Sku);

            stock.Value = stockValue != null?stockValue.Value.ToString("0.####") : "";

            return(stock);
        }