logo
Welcome to our new AbleCommerce forums. As a guest, you may view the information here. To post to this forum, you must have a registered account with us, either as a new user evaluating AbleCommerce or an existing user of the application. For all questions related to the older version of Gold and earlier, please go to AbleCommerce Gold forum. Please use your AbleCommerce username and password to Login. New Registrations are disabled.

Notification

Icon
Error

Options
Go to last post Go to first unread
SteveFeher  
#1 Posted : Monday, August 26, 2019 2:19:38 PM(UTC)
SteveFeher

Rank: Member

Groups: Developers, HelpDesk, Registered
Joined: 11/1/2018(UTC)
Posts: 29

In previous versions of Ablecommerce, we leveraged the SKU value as follows:

In the CONLIB (ASCX) page:

Code:
<a href="<asp:literal id="PDFBrochureLink" runat="server"></asp:literal>" Title="View PDF of a Product Brochure" target="_blank"><img src="/shop/Assets/download_sample.png" style="padding-top:5px; padding-bottom: 5px;" ></a>


In the CONLIB (.CS) page:

Code:
PDFBrochureLink.Text = "/shop/assets/PDFs/"+ _Product.Sku + ".pdf";   // We use the SKU field for the independent .PDF assignment.



Essentially, this enabled us to have a product PDF file that was physically named the same the Product SKU and then easily link to it.

Now that we're converting the site forward to AC Version 9, I'm looking for this same valuation to connect the SKU to a PDF link in a custom Widget Board. However, there's nothing to indicate the option for a SKU in the existing tools.

How can we do this in AC??

Thanks!

Wanna join the discussion?! Login to your AbleCommerce Forums forum account. New Registrations are disabled.

judy at Web2Market  
#2 Posted : Tuesday, August 27, 2019 5:26:40 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 289

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
In Razor syntax in a view, you can do (for want of a better way, if your view isn't using a model that includes the product sku, assuming this will be on the product page):
@using CommerceBuilder.Products
@{

Product product = AbleContext.Container.Resolve<IProductRepository>().Load(PageHelper.GetProductId());
string sku=product.Sku;

Then later on you can call @Html.Raw(sku) or something similar
mazhar  
#3 Posted : Thursday, August 29, 2019 4:43:09 AM(UTC)
mazhar

Rank: Administration

Groups: Admin, Administrators, HelpDesk, System, Authorized User, Developers, Registered
Joined: 10/5/2018(UTC)
Posts: 175

Thanks: 8 times
Was thanked: 17 time(s) in 15 post(s)
You just need to convert the code for MVC. This part of your code which is in code behind can be converted to something like
Code:
PDFBrochureLink.Text = "/shop/assets/PDFs/"+ _Product.Sku + ".pdf";   // We use the SKU field for the independent .PDF assignment.

to
Code:
ViewBag.PDFBrochureLink = "/shop/assets/PDFs/"+ _Product.Sku + ".pdf";   // We use the SKU field for the independent .PDF assignment.


Now update the front end code from this
Code:
<a href="<asp:literal id="PDFBrochureLink" runat="server"></asp:literal>" Title="View PDF of a Product Brochure" target="_blank"><img src="/shop/Assets/download_sample.png" style="padding-top:5px; padding-bottom: 5px;" ></a>

to
Code:
<a href="@ViewBag.PDFBrochureLink" title="View PDF of a Product Brochure" target="_blank"><img src="/shop/Assets/download_sample.png" style="padding-top:5px; padding-bottom: 5px;" ></a>


If these updates were part of an existing out of the box conlib control then in AC9 you may have an action method decorated with RegisterWidget attribute where you will have to make code change to set ViewBag and in its related razor view you will have to make the second change to generate link.

I hope this would be helpful!
mazhar  
#4 Posted : Friday, August 30, 2019 8:57:27 AM(UTC)
mazhar

Rank: Administration

Groups: Admin, Administrators, HelpDesk, System, Authorized User, Developers, Registered
Joined: 10/5/2018(UTC)
Posts: 175

Thanks: 8 times
Was thanked: 17 time(s) in 15 post(s)
For the above changes if you want to place it under the product image then the code changes must be made into ProductImage control. You will find the method called ProductImage in Website/Controllers/ProductController.cs file. Here you will need to set the ViewBag. For HTML change you will have to update Website/Views/Product/_ProductImage.cshtml file.

Another quick way to generate this URL could be to use the HTML snippet along with some javascript to generate the download URL. This is based on the fact that we do output SKU on product details page if it's available for the product. For example, simply create HTML snippet call it PDF Download. Then open HTML editor's source view, you will found it the right side of the toolbar with angle brackets icon. Then paste the following content inside it.
Code:

<a id="pdf-download" href="#" title="View PDF of a Product Brochure" target="_blank" style="display:none;"><img src="/shop/Assets/download_sample.png" style="padding-top:5px; padding-bottom: 5px;" ></a>
<script>
window.onload = function(){
var lists = document.getElementsByClassName("list-unstyled product-info");
if (lists !== undefined || lists.length !== 0) {
    var list = lists[0];
    var spanTags = list.getElementsByTagName("span");
    for (i = 0; i < spanTags.length; i++) {
        var spanTag = spanTags[i];
        if (spanTag.innerHTML.includes("SKU") && (i + 1) < spanTags.length){
            var sku = spanTags[i + 1].innerHTML;
            if (sku) {
                var link = document.getElementById("pdf-download");
                link.href = "/shop/assets/PDFs/"+ sku + ".pdf"
                link.style.display = "block";
            }
        }
    }
}}
</script>

Now save it. Finally drag drop this snippet under product image on product details page. Now if product has sku specified it will generate the download image for PDF having SKU in name.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.