Ejemplo n.º 1
0
        public CatalogProductInfoResponse(catalogProductRepositoryV1GetResponse1 catalogProductInfoResponse)
        {
            if (catalogProductInfoResponse == null ||
                catalogProductInfoResponse.catalogProductRepositoryV1GetResponse == null ||
                catalogProductInfoResponse.catalogProductRepositoryV1GetResponse.result == null)
            {
                return;
            }

            var catalogDataProductInterface = catalogProductInfoResponse.catalogProductRepositoryV1GetResponse.result;

            this.ShortDescription = string.Empty;
            if (!string.IsNullOrWhiteSpace(catalogDataProductInterface.price))
            {
                this.Price = catalogDataProductInterface.price.ToString(CultureInfo.InvariantCulture);
            }
            if (!string.IsNullOrWhiteSpace(catalogDataProductInterface.weight))
            {
                this.Weight = catalogDataProductInterface.weight.ToString(CultureInfo.InvariantCulture);
            }
            this.ProductId = catalogDataProductInterface.id.ToString(CultureInfo.InvariantCulture);

            if (catalogDataProductInterface.customAttributes != null &&
                catalogDataProductInterface.customAttributes.Any())
            {
                this.Description  = GetSimpleStringCustomAttribute(catalogDataProductInterface, "description");
                this.SpecialPrice = GetSimpleStringCustomAttribute(catalogDataProductInterface, "special_price");
                this.CategoryIds  = GetArrayOfStringCustomAttribute(catalogDataProductInterface, "category_ids");

                this.Attributes = catalogDataProductInterface.customAttributes.Select(x => new ProductAttribute(x.attributeCode, GetCustomAttribute(catalogDataProductInterface, x.attributeCode))).ToList();
            }
        }
Ejemplo n.º 2
0
        public virtual async Task <CatalogProductInfoResponse> GetProductInfoAsync(CatalogProductInfoRequest catalogProductInfoRequest, bool throwException = true)
        {
            try
            {
                const int maxCheckCount    = 2;
                const int delayBeforeCheck = 1800000;

                var res           = new catalogProductRepositoryV1GetResponse1();
                var privateClient = this.CreateMagentoCatalogProductRepositoryServiceClient(this.BaseMagentoUrl);

                await ActionPolicies.GetAsync.Do(async() =>
                {
                    var statusChecker = new StatusChecker(maxCheckCount);
                    TimerCallback tcb = statusChecker.CheckStatus;

                    if (privateClient.State != CommunicationState.Opened &&
                        privateClient.State != CommunicationState.Created &&
                        privateClient.State != CommunicationState.Opening)
                    {
                        privateClient = this.CreateMagentoCatalogProductRepositoryServiceClient(this.BaseMagentoUrl);
                    }

                    // we don't need them, since Magento 2.0 returns all attributes
                    //var attributes = new catalogProductRequestAttributes { additional_attributes = custAttributes ?? new string[ 0 ] };

                    using (var stateTimer = new Timer(tcb, privateClient, 1000, delayBeforeCheck))
                    {
                        var catalogProductRepositoryV1GetRequest = new CatalogProductRepositoryV1GetRequest()
                        {
                            sku = catalogProductInfoRequest.Sku
                        };
                        res = await privateClient.catalogProductRepositoryV1GetAsync(catalogProductRepositoryV1GetRequest).ConfigureAwait(false);
                    }
                }).ConfigureAwait(false);

                return(new CatalogProductInfoResponse(res));
            }
            catch (Exception exc)
            {
                if (throwException)
                {
                    throw new MagentoSoapException(string.Format("An error occured during GetProductInfoAsync({0})", catalogProductInfoRequest.ToJson()), exc);
                }
                else
                {
                    return(new CatalogProductInfoResponse(exc));
                }
            }
        }