We are working on a store. But we dont want to use nodes.
It seems like it is possible to send any productsidentifier, but how do I pass along the price for that particular item without using a node with a price as a property?
How do you store your product information? XML? webservice? Something else?
You can implement your own product information extractor, which can deliver all product information using a given productidentifier. To create a product information extractor you will need to create a class that inherits from the XmlNodeProductInformationExtractor AND another class that inherits from the DynamicNodeProductInformationExtractor. Both are equally important. You then overrides the methods and write your own code. Here's an example of how the XmlNodeProductInformationExtractor is overridden.
Note that there are several more methods that need to be overridden.
using System.Linq;
using System.Xml.Linq;
using System.Xml.XPath;
using TeaCommerce.Api.Dependency;
using TeaCommerce.Api.Models;
using TeaCommerce.Umbraco.Web;
using TeaCommerce.Api.Services;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using umbraco.cms.businesslogic.member;
using System.Web;
namespace Muubs.Website.TeaCommerceExtension {
[SuppressDependency( "TeaCommerce.Umbraco.Configuration.InformationExtractors.IXmlNodeProductInformationExtractor", "TeaCommerce.Umbraco.Configuration" )]
publicclassInformationExtractor : TeaCommerce.Umbraco.Configuration.InformationExtractors.XmlNodeProductInformationExtractor {
public InformationExtractor( IStoreService storeService, ICurrencyService currencyService, IVatGroupService vatGroupService )
: base( storeService, currencyService, vatGroupService ) {
}
publicoverride OriginalUnitPriceCollection GetOriginalUnitPrices( XPathNavigator model, bool useCachedInformation = true ) {
long storeId = ProductService.Instance.GetStoreId( model.GetAttribute( "id", "" ) );
int memberID = Member.CurrentMemberId();
if ( memberID == 0 || storeId == 1 ) {
returnbase.GetOriginalUnitPrices( model, useCachedInformation );
}
string memberPriceGroupId = ( string )HttpContext.Current.Session["memberPriceGroupId"];
Currency currency = TC.GetCurrentCurrency( storeId );
string masterRelationID = model.SelectSingleNode( "masterRelation" ).Value;
ContentService contentService = new ContentService();
IContent masterRelationNode = contentService.GetById( int.Parse( masterRelationID ) );
OriginalUnitPriceCollection r = new OriginalUnitPriceCollection();
if ( masterRelationNode != null ) {
object priceXML = masterRelationNode.GetValue( "priceXML" );
XDocument priceDocument = XDocument.Parse( priceXML.ToString() );
XElement priceElement = priceDocument.XPathSelectElement( "//Group [@GroupId = " + memberPriceGroupId + "]" );
if ( priceElement.Attribute( "Price" ) != null ) {
r.Add( new OriginalUnitPrice( decimal.Parse( priceElement.Attribute( "Price" ).Value ), currency.Id ) );
} else {
r.Add( new OriginalUnitPrice( 0M, currency.Id ) );
}
}
return r;
}
}
}
Working without nodes?
Hello,
We are working on a store. But we dont want to use nodes.
It seems like it is possible to send any productsidentifier, but how do I pass along the price for that particular item without using a node with a price as a property?
//Kalle
Hi Kalle,
How do you store your product information? XML? webservice? Something else?
You can implement your own product information extractor, which can deliver all product information using a given productidentifier. To create a product information extractor you will need to create a class that inherits from the XmlNodeProductInformationExtractor AND another class that inherits from the DynamicNodeProductInformationExtractor. Both are equally important. You then overrides the methods and write your own code. Here's an example of how the XmlNodeProductInformationExtractor is overridden.
Note that there are several more methods that need to be overridden.
Hope that's the answer you are seeking.
/Rune
Hi Kalle
Did Rune's answer get you in the right direction? What is your business case - it might help us to understand what you want to do :)
Kind regards
Anders
is working on a reply...