Skip to main content
added 48 characters in body
Source Link
Cassie
  • 193
  • 10
 public with sharing class ProductPagesController {
public List<Product__c> shoppingCart { set; get; }
public Set<String> selectedIds { set; get; }
private String currentPage =   ApexPages.currentPage().getParameters().get('Id');
public Id chosenItemId { set; get; }
public List<Product__c> tvsList { set; get; }

public ProductPagesController() {
    renderTV = false;
    renderShoppingCart = false;
    tvsList = selectTVsList();
    selectedIds = new Set<String>();
    shoppingCart = new List<Product__c>();
}

private Product__c selectedItems(Id itemId) {
    Product__c items = [
            SELECT Id
                    , Name
                    , Price__c
                    , Description__c
                    , Image__c
                    , Quantity__c
            FROM Product__c
            WHERE Id=:itemId
    ];
    return items;
}

 public PageReference addProductToShoppingCart() {
     Product__c shoppingCartItem;
        for(Id itemId : selectedIds){
            shoppingCartItem = selectedItems(itemId);
            shoppingCart.add(shoppingCartItem);
        }

        update shoppingCart;
        return null;
    }
}
 public with sharing class ProductPagesController {
public List<Product__c> shoppingCart { set; get; }
public Set<String> selectedIds { set; get; }
private String currentPage =   ApexPages.currentPage().getParameters().get('Id');
public Id chosenItemId { set; get; }
public List<Product__c> tvsList { set; get; }

public ProductPagesController() {
    renderTV = false;
    renderShoppingCart = false;
    tvsList = selectTVsList();
    selectedIds = new Set<String>();
}

private Product__c selectedItems(Id itemId) {
    Product__c items = [
            SELECT Id
                    , Name
                    , Price__c
                    , Description__c
                    , Image__c
                    , Quantity__c
            FROM Product__c
            WHERE Id=:itemId
    ];
    return items;
}

 public PageReference addProductToShoppingCart() {
     Product__c shoppingCartItem;
        for(Id itemId : selectedIds){
            shoppingCartItem = selectedItems(itemId);
            shoppingCart.add(shoppingCartItem);
        }

        update shoppingCart;
        return null;
    }
}
 public with sharing class ProductPagesController {
public List<Product__c> shoppingCart { set; get; }
public Set<String> selectedIds { set; get; }
private String currentPage =   ApexPages.currentPage().getParameters().get('Id');
public Id chosenItemId { set; get; }
public List<Product__c> tvsList { set; get; }

public ProductPagesController() {
    renderTV = false;
    renderShoppingCart = false;
    tvsList = selectTVsList();
    selectedIds = new Set<String>();
    shoppingCart = new List<Product__c>();
}

private Product__c selectedItems(Id itemId) {
    Product__c items = [
            SELECT Id
                    , Name
                    , Price__c
                    , Description__c
                    , Image__c
                    , Quantity__c
            FROM Product__c
            WHERE Id=:itemId
    ];
    return items;
}

 public PageReference addProductToShoppingCart() {
     Product__c shoppingCartItem;
        for(Id itemId : selectedIds){
            shoppingCartItem = selectedItems(itemId);
            shoppingCart.add(shoppingCartItem);
        }

        update shoppingCart;
        return null;
    }
}
deleted 128 characters in body; edited tags
Source Link
battery.cord
  • 8.9k
  • 8
  • 32
  • 59

Hello! I`m developing a website on Salesforce. And I have 4 main blocks pages on one page with lists of products in different categories and Shopping cart page. 

I want by click on the custom button Add to cartAdd to cart (near each item on the product page) put selected items into the list or any other collection, which should be displayed on the Shopping cart page. 

I have this problem - every timeeverytime I click on the button my list of items stays empty. I tried different ways, but all I could get is only one item displayed. Somehow, selected items are not passed to the page, though I select them by chosen ID. I would really appreciate some help, cause I am trying to fix this for 2 days!

Hello! I`m developing a website on Salesforce. And I have 4 main blocks pages on one page with lists of products in different categories and Shopping cart page. I want by click on the custom button Add to cart (near each item on the product page) put selected items into the list or any other collection, which should be displayed on the Shopping cart page. I have this problem - every time I click on the button my list of items stays empty. I tried different ways, but all I could get is only one item displayed. Somehow, selected items are not passed to the page, though I select them by chosen ID. I would really appreciate some help, cause I am trying to fix this for 2 days!

I have 4 main blocks pages on one page with lists of products in different categories and Shopping cart page. 

I want by click on the custom button Add to cart (near each item on the product page) put selected items into the list or any other collection, which should be displayed on the Shopping cart page. 

I have this problem - everytime I click on the button my list of items stays empty. I tried different ways, but all I could get is only one item displayed. Somehow, selected items are not passed to the page, though I select them by chosen ID.

added 2 characters in body
Source Link
Cassie
  • 193
  • 10
 public with sharing class ProductPagesController {
public List<Product__c> shoppingCart { set; get; }
public Set<String> selectedIds { set; get; }
private String currentPage =   ApexPages.currentPage().getParameters().get('Id');
public Id chosenItemId { set; get; }
public List<Product__c> tvsList { set; get; }

public ProductPagesController() {
    renderTV = false;
    renderShoppingCart = false;
    tvsList = selectTVsList();
    selectedIds = new Set<String>();
}

private List<Product__c>Product__c selectedItems(Id itemId) {
    List<Product__c>Product__c items = [
            SELECT Id
                    , Name
                    , Price__c
                    , Description__c
                    , Image__c
                    , Quantity__c
            FROM Product__c
            WHERE Id=:chosenItemIditemId
    ];
    return items;
}

 public PageReference addProductToShoppingCart() {
 
    if(currentPage == null){
        PageReference pageRef = new PageReference('/apex/ShoppingCart');
        pageRef.setRedirect(true);
        shoppingCart = selectedItems();
        return pageRef;
    }elseProduct__c {
shoppingCartItem;
        for (Product__cId productitemId : productsListselectedIds) {
            if (product.Quantity__cshoppingCartItem >= 0selectedItems(itemId) {;
                shoppingCart = selectedItems.add(shoppingCartItem);
 
            } 

        }
update shoppingCart;
        return null;
    }
}
<apex:form id="tvsForm">
        <apex:outputPanel id="tvsDetail">
            <apex:pageBlock title="TVs" id="tvsBlock">
                <apex:pageBlockTable value="{!tvsList}" var="tv">
                    <apex:column >
                        <apex:commandLink value="{!tv.Name}" >
                            <apex:param name="id" value="{!tv.Id}"/>
                        </apex:commandLink>
                        <apex:pageBlockSection >
                            <apex:image value="{!URLFOR($Resource.TV, tvsImages[tv.Name])}" id="tvImage"/>
                        </apex:pageBlockSection>
                        <apex:pageBlockSection >
                            <apex:outputText value="{!tv.Price__c}" id="tvPrice"/><br/>
                            <apex:outputText value="{!tv.Description__c}"/>
                        </apex:pageBlockSection>
                        <br/>
                        <apex:commandButton value="Add to cart" action="{!addProductToShoppingCart}" id="monitorButton" reRender="cartForm">
                            <apex:param name="itemsId" value="{!tv.Id}" assignTo="{!chosenItemIdselectedIds}"></apex:param>

                        </apex:commandButton>
                        <br/><br/>
                    </apex:column>
                </apex:pageBlockTable>

                <apex:pageBlockSection >
                    <apex:outputText value="There are {!tvsQuantity} products in this category" id="productsNumber"/><br/>
                </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:outputPanel>
    </apex:form>
 public with sharing class ProductPagesController {
public List<Product__c> shoppingCart { set; get; }
private String currentPage = ApexPages.currentPage().getParameters().get('Id');
public Id chosenItemId { set; get; }

private List<Product__c> selectedItems() {
    List<Product__c> items = [
            SELECT Id
                    , Name
                    , Price__c
                    , Description__c
                    , Image__c
                    , Quantity__c
            FROM Product__c
            WHERE Id=:chosenItemId
    ];
    return items;
}

 public PageReference addProductToShoppingCart() {
 
    if(currentPage == null){
        PageReference pageRef = new PageReference('/apex/ShoppingCart');
        pageRef.setRedirect(true);
        shoppingCart = selectedItems();
        return pageRef;
    }else {

        for (Product__c product : productsList) {
            if (product.Quantity__c > 0) {
                shoppingCart = selectedItems();
 
            }
        }

        return null;
    }
}
<apex:form id="tvsForm">
        <apex:outputPanel id="tvsDetail">
            <apex:pageBlock title="TVs" id="tvsBlock">
                <apex:pageBlockTable value="{!tvsList}" var="tv">
                    <apex:column >
                        <apex:commandLink value="{!tv.Name}" >
                            <apex:param name="id" value="{!tv.Id}"/>
                        </apex:commandLink>
                        <apex:pageBlockSection >
                            <apex:image value="{!URLFOR($Resource.TV, tvsImages[tv.Name])}" id="tvImage"/>
                        </apex:pageBlockSection>
                        <apex:pageBlockSection >
                            <apex:outputText value="{!tv.Price__c}" id="tvPrice"/><br/>
                            <apex:outputText value="{!tv.Description__c}"/>
                        </apex:pageBlockSection>
                        <br/>
                        <apex:commandButton value="Add to cart" action="{!addProductToShoppingCart}" id="monitorButton" reRender="cartForm">
                            <apex:param name="itemsId" value="{!tv.Id}" assignTo="{!chosenItemId}"></apex:param>

                        </apex:commandButton>
                        <br/><br/>
                    </apex:column>
                </apex:pageBlockTable>

                <apex:pageBlockSection >
                    <apex:outputText value="There are {!tvsQuantity} products in this category" id="productsNumber"/><br/>
                </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:outputPanel>
    </apex:form>
 public with sharing class ProductPagesController {
public List<Product__c> shoppingCart { set; get; }
public Set<String> selectedIds { set; get; }
private String currentPage =   ApexPages.currentPage().getParameters().get('Id');
public Id chosenItemId { set; get; }
public List<Product__c> tvsList { set; get; }

public ProductPagesController() {
    renderTV = false;
    renderShoppingCart = false;
    tvsList = selectTVsList();
    selectedIds = new Set<String>();
}

private Product__c selectedItems(Id itemId) {
    Product__c items = [
            SELECT Id
                    , Name
                    , Price__c
                    , Description__c
                    , Image__c
                    , Quantity__c
            FROM Product__c
            WHERE Id=:itemId
    ];
    return items;
}

 public PageReference addProductToShoppingCart() {
     Product__c shoppingCartItem;
        for(Id itemId : selectedIds){
            shoppingCartItem = selectedItems(itemId);
            shoppingCart.add(shoppingCartItem);
        } 

        update shoppingCart;
        return null;
    }
}
<apex:form id="tvsForm">
        <apex:outputPanel id="tvsDetail">
            <apex:pageBlock title="TVs" id="tvsBlock">
                <apex:pageBlockTable value="{!tvsList}" var="tv">
                    <apex:column >
                        <apex:commandLink value="{!tv.Name}" >
                            <apex:param name="id" value="{!tv.Id}"/>
                        </apex:commandLink>
                        <apex:pageBlockSection >
                            <apex:image value="{!URLFOR($Resource.TV, tvsImages[tv.Name])}" id="tvImage"/>
                        </apex:pageBlockSection>
                        <apex:pageBlockSection >
                            <apex:outputText value="{!tv.Price__c}" id="tvPrice"/><br/>
                            <apex:outputText value="{!tv.Description__c}"/>
                        </apex:pageBlockSection>
                        <br/>
                        <apex:commandButton value="Add to cart" action="{!addProductToShoppingCart}" id="monitorButton" reRender="cartForm">
                            <apex:param name="itemsId" value="{!tv.Id}" assignTo="{!selectedIds}"></apex:param>

                        </apex:commandButton>
                        <br/><br/>
                    </apex:column>
                </apex:pageBlockTable>

                <apex:pageBlockSection >
                    <apex:outputText value="There are {!tvsQuantity} products in this category" id="productsNumber"/><br/>
                </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:outputPanel>
    </apex:form>
added 2 characters in body
Source Link
Cassie
  • 193
  • 10
Loading
Adding apex tag for format
Link
Martin Lezer
  • 7.3k
  • 5
  • 27
  • 41
Loading
Source Link
Cassie
  • 193
  • 10
Loading