public IViewComponentResult ProductDetailsAfterBreadcrumb(EditorPageModel editorPageModel)
        {
            var productId        = editorPageModel.ProductId;
            var quantity         = editorPageModel.Quantity;
            var updateCartItemId = editorPageModel.UpdateCartItemId;

            var id      = productId;
            var product = _productService.GetProductById(id);

            if (product != null && _ccService.IsProductForCc(product))
            {
                var editorName = _ccService.GetEditorDefinition(product);
                var configName = _ccService.GetEditorConfiguration(product);

                var editorJsonData = _ccService.GetEditor(editorName);
                var settings       = _settingService.LoadSetting <CcSettings>();
                settings.CustomersCanvasApiKey = "";
                settings.OrderExportPath       = "";
                settings.DesignFileName        = "";
                var model = new CcEditorLoaderModel
                {
                    PluginSettings   = settings,
                    ProductDetails   = GetProductDetails(id, updateCartItemId),
                    ProductId        = id,
                    Editor           = editorJsonData.ToJson(),
                    Config           = editorJsonData.GetConfigByTitle(configName).ToJson(),
                    Path             = editorJsonData.VirtualPath,
                    EditorFolder     = editorJsonData.FolderName,
                    UpdateCartItemId = updateCartItemId,
                    CcData           = null,
                    Quantity         = quantity,
                    Language         = _workContext.WorkingLanguage.LanguageCulture.Split('-')[0],
                    Currency         = new CurrencyModel()
                    {
                        Code = _workContext.WorkingCurrency.CurrencyCode, Locale = _workContext.WorkingLanguage.LanguageCulture
                    }
                };
                model.ProductDetails.PageShareCode = "";

                var userModel = new UserModel();
                userModel.UserGuid        = _workContext.CurrentCustomer.CustomerGuid.ToString().Replace("-", "");
                userModel.UserId          = _workContext.CurrentCustomer.Id;
                userModel.IsAuthenticated = User.Identity.IsAuthenticated;
                model.User = userModel;

                if (updateCartItemId != 0)
                {
                    var ccIdAttribute = model.ProductDetails.ProductAttributes.FirstOrDefault(x => x.ProductAttributeId == _customersCanvasSettings.CcIdAttributeId);
                    int designId      = 0;
                    if (ccIdAttribute != null)
                    {
                        if (Int32.TryParse(ccIdAttribute.DefaultValue, out designId))
                        {
                            model.CcData = _ccService.GetDesign(designId);
                        }
                    }
                }

                return(View("~/Plugins/Widgets.CustomersCanvas/Views/Product/EditorScripts.cshtml", model));
            }

            return(null);
        }
コード例 #2
0
        public List <ProductFileModel> GetProductFiles(int orderItemID, string stateId, string pType, int ccId, string webPlatform = "NOP")
        {
            var environment = getEnvironment();
            List <ProductFileModel> productFiles = new List <ProductFileModel>();

            webPlatform = webPlatform.ToUpper();
            switch (webPlatform)
            {
            case "NOP":
            {
                Dictionary <string, Object> paramDicEx = new Dictionary <string, Object>();
                paramDicEx.Add("@nopOrderItemID", orderItemID);

                DBManager manager = new DBManager();
                string    select  = "EXEC usp_getTblNOPProductionFiles_byOrderItemId @nopOrderItemID";
                DataView  result  = manager.GetParameterizedDataView(select, paramDicEx);

                if (result.Count > 0)
                {
                    foreach (DataRowView row in result)
                    {
                        ProductFileModel file = new ProductFileModel();
                        file.product.productType        = (string)row["ProductType"];
                        file.product.productionFileName = (string)row["FileName"];
                        if (pType == file.product.productType)
                        {
                            productFiles.Add(file);
                        }
                    }
                    var     design    = _ccService.GetDesign(ccId);
                    dynamic hiResUrls = JsonConvert.DeserializeObject <Object>(design.DownloadUrlsJson);
                    foreach (ProductFileModel productFile in productFiles.ToList())
                    {
                        //rules will change per product type
                        switch (productFile.product.productType)
                        {
                        case "notecard":
                            if (pType != "notecard")
                            {
                                productFiles.Remove(productFile);
                                break;
                            }
                            foreach (string url in hiResUrls)
                            {
                                var urlStateId = url.Split('/')[url.Split('/').Count() - 2];
                                if (urlStateId != stateId)
                                {
                                    continue;
                                }
                                var index      = url.Split('/').Last <string>().Split('_').First <string>();
                                var fileMiddle = productFile.product.productionFileName.Split('-')[1];
                                switch (index)
                                {
                                case "0":
                                    //front
                                    if (fileMiddle.StartsWith("CF"))
                                    {
                                        productFile.product.hiResPDFURL = url;
                                    }
                                    break;

                                case "1":
                                    //greeting
                                    if (fileMiddle.StartsWith("G"))
                                    {
                                        productFile.product.hiResPDFURL = url;
                                    }
                                    break;

                                case "2":
                                    //back
                                    if (fileMiddle.StartsWith("CB"))
                                    {
                                        productFile.product.hiResPDFURL = url;
                                    }
                                    break;
                                }
                            }
                            break;

                        case "envelope":
                            if (pType != "envelope")
                            {
                                productFiles.Remove(productFile);
                                break;
                            }
                            foreach (string url in hiResUrls)
                            {
                                var urlStateId = url.Split('/')[url.Split('/').Count() - 2];
                                if (urlStateId != stateId)
                                {
                                    continue;
                                }
                                var index      = url.Split('/').Last <string>().Split('_').First <string>();
                                var fileMiddle = productFile.product.productionFileName.Split('-')[1];
                                if (fileMiddle[0] != 'E')
                                {
                                    continue;
                                }
                                switch (index)
                                {
                                case "0":
                                    //front
                                    if (fileMiddle[2] == 'F')
                                    {
                                        productFile.product.hiResPDFURL = url;
                                    }
                                    break;

                                case "1":
                                    //back
                                    if (fileMiddle[2] == 'B')
                                    {
                                        productFile.product.hiResPDFURL = url;
                                    }
                                    break;
                                }
                            }
                            break;

                        default:
                            break;
                        }
                    }
                }
                else
                {
                    throw new Exception("Can't find production files for order item - " + orderItemID);
                }
                break;
            }

            default:
            {
                Dictionary <string, Object> paramDicEx = new Dictionary <string, Object>();
                paramDicEx.Add("@OPID", orderItemID);

                DBManager manager         = new DBManager(_gbsOrderSettings.HOMConnectionString);
                string    select          = "EXEC usp_getCanvasStateFileInfo @OPID";
                DataView  orderItemResult = manager.GetParameterizedDataView(select, paramDicEx);
                if (orderItemResult.Count > 0)
                {
                    foreach (DataRowView row in orderItemResult)
                    {
                        ProductFileModel file = new ProductFileModel();
                        file.product.productionFileName = (string)row["frontFile"];
                        if (row["hiResUrlFront"] != System.DBNull.Value)
                        {
                            var ub = new UriBuilder(new Uri((string)row["hiResUrlFront"]));
                            ub.Scheme = "https";
                            file.product.hiResPDFURL = ub.Uri.AbsoluteUri;
                        }
                        if (file.product.productionFileName != "not saved")
                        {
                            productFiles.Add(file);
                        }
                        ;
                        file = new ProductFileModel();
                        file.product.productionFileName = (string)row["backFile"];
                        if (row["hiResUrlBack"] != System.DBNull.Value)
                        {
                            var ub = new UriBuilder(new Uri((string)row["hiResUrlBack"]));
                            ub.Scheme = "https";
                            file.product.hiResPDFURL = ub.Uri.AbsoluteUri;
                        }
                        if (file.product.productionFileName != "not saved")
                        {
                            productFiles.Add(file);
                        }
                        ;
                    }
                }
                else
                {
                    throw new Exception("Can't find order item - " + orderItemID);
                }

                break;
            }
            }
            return(productFiles);
        }