Do you want to have the functionality of "Products to Cart" Or do you want to Add Records from one object to other. There's a huge difference between both. Do let me know.
public with sharing class proj1{ public String Product2{ get; set; }
public list <Product2> acc {get;set;} public string searchstring {get;set;} public list<Selectoption> listOfStrings {get; set;}
public proj1( ) { listOfStrings = new List<Selectoption>(); for(Product2 a: [SELECT Name, ProductCode,IsActive From Product2 LIMIT 50]) listOfStrings.add(new selectoption(a.name,a.name)); // listOfStrings.add(a.name);
}
public void search(){ string searchquery='select name,ProductCode,Quantity__c,UnitPrice__c from product2 where name like \'%'+searchstring +'%\' Limit 30'; acc= Database.query(searchquery); }
Do you want to have the functionality of "Products to Cart" Or do you want to Add Records from one object to other. There's a huge difference between both. Do let me know.
Thanks.
by calling cart as new object....i.e,copy the records from product object to cart object
Or you want us to write the whole code?
Regards.
Till diplaying the records its completed....but addtocart programming i need sir.
<apex:page Controller="proj1" docType="html-5.0" >
<apex:form >
<apex:selectList size="1" value="{!searchstring}">
<apex:selectOptions value="{!listOfStrings }"/>
</apex:selectList>
<apex:commandButton value="Search records" action="{!search}" />
<apex:commandButton value="Clear records" action="{!clear}" />
<apex:pageBlock title="Search Result">
<apex:pageblockTable value="{!acc}" var="a">
<apex:column value="{!a.name}"/>
<apex:column value="{!a.ProductCode }"/>
<apex:column value="{!a.Quantity__c}"/>
<apex:column value="{!a.UnitPrice__c}"/>
<apex:column > <apex:commandButton value="AddToCart" /> </apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
CONTROLLER
public with sharing class proj1{
public String Product2{ get; set; }
public list <Product2> acc {get;set;}
public string searchstring {get;set;}
public list<Selectoption> listOfStrings {get; set;}
public proj1( ) {
listOfStrings = new List<Selectoption>();
for(Product2 a: [SELECT Name, ProductCode,IsActive From Product2 LIMIT 50])
listOfStrings.add(new selectoption(a.name,a.name));
// listOfStrings.add(a.name);
}
public void search(){
string searchquery='select name,ProductCode,Quantity__c,UnitPrice__c from product2 where name like \'%'+searchstring +'%\' Limit 30';
acc= Database.query(searchquery);
}
public void clear(){
acc.clear();
}
}