Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kalle Ekstrand 181 posts 259 karma points c-trib
    Jul 08, 2013 @ 16:20
    Kalle Ekstrand
    0

    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

  • Rune Grønkjær 1296 posts 2863 karma points
    Jul 08, 2013 @ 17:34
    Rune Grønkjær
    0

    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.

    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" )]
      public class InformationExtractor : TeaCommerce.Umbraco.Configuration.InformationExtractors.XmlNodeProductInformationExtractor {
        public InformationExtractor( IStoreService storeService, ICurrencyService currencyService, IVatGroupService vatGroupService )
          : base( storeService, currencyService, vatGroupService ) {
        }
    
        public override OriginalUnitPriceCollection GetOriginalUnitPrices( XPathNavigator model, bool useCachedInformation = true ) {
          long storeId = ProductService.Instance.GetStoreId( model.GetAttribute( "id""" ) );
    
          int memberID = Member.CurrentMemberId();
    
          if ( memberID == 0 || storeId == 1 ) {
            return base.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;
        }
    
      }
    }

    Hope that's the answer you are seeking.

    /Rune

  • Anders Burla Johansen 2560 posts 8256 karma points
    Jul 14, 2013 @ 01:44
    Anders Burla Johansen
    0

    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 

Please Sign in or register to post replies

Write your reply to:

Draft