Announcement

Collapse
No announcement yet.

Display trade discount to logged in customers

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Display trade discount to logged in customers

    Hi All

    I'm trying to display a trade discount to logged in customers. I've added the following code to the product layout to show, for example:

    RRP (Ex) £17.5 - RRP (Inc) £21.00 - TRADE (ex) £11.38 - % off RRP = 35%

    under each product. The page is set out as a product list with single add to cart button.

    It seems to be working apart from calculating the "% off RRP".

    As it's the logged in customer price I am using in the calculation, I have used javascript to work out the discount. The only way I know to get to the customer price is to use <td id="trade"> in the cell containing <actinic:variable name="PriceListRetail" /> in the product layout. But this only picks up the value from the first product in the list and displays the same discount for all the products listed.

    Any help would be much appreciated.

    Thank
    Lee

    Code:
    <table width="100%" cellspacing="0" cellpadding="1" style="border-top:dotted 1px #003399;">
      <tr>
         <td width="13%" align="left" valign="middle" style="height:26px;"><actinic:variable name="RealTimeStockDisplay" /></td>
         <td id="retailex" width="21%" align="left" valign="middle">
           RRP (Ex) <Actinic:PRICES> £<actinic:variable name="ProductPriceRaw" /></Actinic:PRICES></td>
         <td width="22%" align="left" valign="middle">
           <Actinic:PRICES>
           <actinic:block php="true">
           $rawprice = <actinic:variable name="ProductPriceRaw" selectable="false" />;
           {
           $rrpincvat = number_format(($rawprice*1.2), 2, ".", " ");
           echo "RRP (Inc) £$rrpincvat";
           }
           </actinic:block>
           </Actinic:PRICES>
         </td>
         <td width="22%" align="left" valign="middle">TRADE (ex) 
           <Actinic:PRICES PROD_REF="<actinic:variable Name="ProductID" />" RETAIL_PRICE_PROMPT="<Actinic:Variable Name="ProductPriceDescription"/>">
           <actinic:variable name="PriceListRetail" />
           </Actinic:PRICES>
         </td>
         <td width="22%" align="left" valign="middle">
         % off RRP =    
         <script>
           var tradeprice = document.getElementById('trade').innerHTML.replace(/[^\d\.]/g, '');
           var retailpriceex = document.getElementById('retailex').innerHTML.replace(/[^\d\.]/g, '');
           var tradedisc = ((retailpriceex-tradeprice)/retailpriceex)*100;
           var tradedisc = tradedisc * 10;
           var tradedisc = Math.round(tradedisc);
           var tradedisc = tradedisc / 10;
           document.write(tradedisc + '%');
         </script>      
         </td>
       </tr>
    </table>

    #2
    There's no id="trade" in your published code, but you refer to it in the JavaScript. It would help to see the full code of the layout you use it in.

    Also, you cannot use the same id tag more than once on a page. It's invalid HTML and document.getElementById will be unreliable in such cases.

    And, as always, a link to a problem page would help a lot.
    Norman - www.drillpine.biz
    Edinburgh, U K / Bitez, Turkey

    Comment


      #3
      A suggestion (untested):

      Your <actinic:variable name="PriceListRetail" /> field within
      Code:
      <td class="trade_<actinic:variable name="ProductPriceRaw" />" >PRICELISTRETAIL HERE</td>
      JavaScript that runs once only at bottom of page:
      Code:
      var tdcells = document.getElementsByTagName('td');
      for (var i=0; i<tdcells.length; i++)
      	{
      	if (tdcells[i].className.indexOf('trade_') > -1)
      		{
      		var ppraw = tdcells[i].className.replace(/trade_/, '');
      		var inner = tdcells[i].innerHTML;
      		var tradeprice = inner.replace(/[^\d\.]/g, '');
      		var percentoff = CALCULATE AND STRING FORMAT DISCOUNT PERCENTAGE USING ppraw and tradeprice
      		// add the percentage off info to the innerHTML
      		tdcells[i].innerHTML = inner + percentoff;
      		}
      	}
      Norman - www.drillpine.biz
      Edinburgh, U K / Bitez, Turkey

      Comment


        #4
        Thanks Norman, I'm just looking at your suggestions (might take a while to work out, I don't know javascript) but in the meantime here is the full code. The page it is used on is:
        http://www.legerereeds.co.uk/supplie...saxophone.html

        when logged in with trade access you get a second line under each product with the trade info:
        RRP (Ex) £17.5 - RRP (Inc) £21.00 - TRADE (ex) £11.38 - % off RRP = 35%


        Code:
        <actinic:block if="%3cactinic%3avariable%20name%3d%22IsProductFormUsed%22%20%2f%3e">
              <form method="post" action="<actinic:variable name="OnlineScriptURL" value="Shopping Cart Script URL" />">
                 <input type="hidden" name="SID" value="<Actinic:Variable Name="SectionID"/>" />
                 <input type="hidden" name="PAGE" value="PRODUCT" />          
                 <input type="hidden" name="PAGEFILENAME" value="<actinic:variable name="SectionPageName" />" />
                 <Actinic:SECTION BLOB='<Actinic:Variable Name="SectionCatFile"/>'/>
                 <actinic:block if="%3cactinic%3avariable%20name%3d%22IsHostMode%22%20%2f%3e">
                    <!-- Hidden field when in trial mode -->
                    <input type="hidden" name="SHOP" value="<Actinic:Variable Name="HiddenFields"/>" />
                 </actinic:block>
        </actinic:block>
        <br/>
        <table width="100%" cellspacing="0" cellpadding="0" border="0">
                <tr>
                   <td colspan="2"><img src="round_tl.gif" width="8" height="8" /></td>
                   <td valign="top"><img src="box_line.gif" width="100%" height="2" /></td>
                   <td colspan="2"><img src="round_tr.gif" width="8" height="8" /></td>
                </tr> 
                
                <tr>
                   <td width="2" height="100%" align="left" bgcolor="#003399"><img src="box_line.gif" width="2" height="100%" /></td>
                   <td width="6" align="left">&nbsp;</td>
                   <td>    
        
        <table width="100%" cellspacing="0" cellpadding="1" border="0">
           <tr>
               <td width="65%" align="left" valign="top">
                 <Actinic:Variable Name="ProductDescription"/><br/><br/>RRP 
        <span class='text_srp'>
        <actinic:block php="true">
        
        $rawprice = <actinic:variable name="ProductPriceRaw" selectable="false" />;
        {
          $rrpincvat = number_format(($rawprice*1.2), 2, ".", " ");
            echo " £$rrpincvat";
          }
        </actinic:block>
        </span>
        Inc VAT<br/><br/>
              </td>
              <td width="25%" align="center" valign="middle">
                 <actinic:variable name="ProductImageLayout" />
              </td>
           </tr>
        </table>
        
        			</td>
        			  <td width="6" align="right">&nbsp;</td>
                   <td width="2" height="100%" align="right" bgcolor="#003399"><img src="box_line.gif" width="2" height="100%" /></td>
                </tr> 
                
                <tr>
                   <td width="2" height="100%" align="left" bgcolor="#003399"><img src="box_line.gif" width="2" height="100%" /></td>
                   <td width="6" align="left">&nbsp;</td>
                   <td>
                   
           <table width="100%" cellspacing="0" cellpadding="0" border="0">
                <tr>
                <td width="13%" align="left" valign="bottom">Item Code</td>
                <td width="55%" align="left" valign="bottom">Description</td>
                <td width="23%" align="right" valign="bottom">Price in <acronym title="Great Britain Pound Sterling">GBP</acronym> <abbr title="Excluding">Excl</abbr> <acronym title="Value Added Tax">VAT</acronym></td>
                <td width="9%" align="center" valign="bottom">Qty:</td>
                </tr>
          	</table>
          				</td>
         			  <td width="6" align="right">&nbsp;</td>
                   <td width="2" height="100%" align="right" bgcolor="#003399"><img src="box_line.gif" width="2" height="100%" /></td>
                </tr> 
         	
         
         			
        			<tr>
        			 <td width="2" height="100%" align="left" bgcolor="#003399"><img src="box_line.gif" width="2" height="100%" /></td>
        			 <td colspan="3" style="border-top:dotted 1px #003399;"></td>
                  <td width="2" height="100%" align="right" bgcolor="#003399"><img src="box_line.gif" width="2" height="100%" /></td>
        			</tr> 
        	
        
        
         
                <tr>
                   <td width="2" height="100%" align="left" bgcolor="#003399"><img src="box_line.gif" width="2" height="100%" /></td>
                   <td width="6" align="left">&nbsp;</td>
                   <td>       
           
        <!-- Unregistered Start -->
        <Actinic:NOTINB2B>
        <table width="100%" cellspacing="0" cellpadding="1" border="0">
           <tr>
           
              <td width="13%" align="left" valign="middle">
                 <a name="<Actinic:Variable Name="EncodedProductAnchor"/>"></a>
                 <b><actinic:variable name="ProductReference" /></b>&nbsp;&nbsp;
              </td>
                 
              <td width="57%" align="left" valign="middle">
                 <b><Actinic:Variable Name="ProductName"/></b>&nbsp;&nbsp;
              </td>
              
              <td width="23%" align="right" valign="middle">
        		</td>
              
              <td width="7%" align="right" valign="middle">
        			<span TITLE="header=[<center>Login Required</center>] body=[Please login for wholesale prices.<br/>Wholesale prices for these products are available to UK retail traders in the music industry and professional instrument repair shops only]"><a href="login.html">Login</a></span>
              </td>
              
           </tr>
        
        </table>
        </Actinic:NOTINB2B>
        <!-- Unregistered End -->
        
        <style>
        .sched1 {display:none}
        .sched3 {display:none}
        </style>
        
        <Actinic:SHOWFORPRICESCHEDULE Schedules="1" HTML="<style>.sched1 {display:block}</style>" />
        <Actinic:SHOWFORPRICESCHEDULE Schedules="3" HTML="<style>.sched3 {display:block}</style>" />
        
        <!-- Retail Start -->
        <div class="sched1">
        <table width='100%' cellspacing='0' cellpadding='1' border='0'>
           <tr>
           
              <td width='13%' align='left' valign='middle'>
                 <a name='<Actinic:Variable Name='EncodedProductAnchor'/>'></a>
                 <b><actinic:variable name='ProductReference' /></b>&nbsp;&nbsp;
              </td>
                 
              <td width='57%' align='left' valign='middle'>
                 <b><Actinic:Variable Name='ProductName'/></b>&nbsp;&nbsp;
              </td>
              
              <td width='23%' align='right' valign='middle'>
        		</td>
              
              <td width='7%' align='right' valign='middle'>
        			<span TITLE='header=[<center>Dealer Login Required</center>] body=[Your online account does not have dealer status.  If you are a UK retail trader in the music industry or a professional instrument repair shop, please apply for your status to be changed]'><a href='trade_enquiry.html'>Apply</a></span>
              </td>
              
           </tr>
        
        </table>
        </div>
        <!-- Retail End -->
        
        <!-- Trade Start -->
        <div class="sched3">
        <table width="100%" cellspacing="0" cellpadding="1" border="0">
           <tr>
           
              <td width='13%' align='left' valign='middle'>
                 <a name='<Actinic:Variable Name='EncodedProductAnchor'/>'></a>
                 <b><actinic:variable name='ProductReference' /></b>&nbsp;&nbsp;
              </td>
                 
              <td width='57%' align='left' valign='middle'>
                 <b><Actinic:Variable Name='ProductName'/></b>&nbsp;&nbsp;
              </td>
              
              <td id="trade" width='20%' align='right' valign='middle'>
        
                 <actinic:block if="%3cactinic%3avariable%20name%3d%22IsCustomerMessageUsed%22%20%2f%3e">
                    <Actinic:PRICE_EXPLANATION PROD_REF="<actinic:variable Name="ProductID" />" COMPONENTID=-1><Actinic:NOTINB2B><span TITLE="header=[<center>Login Required</center>] body=[Please login for wholesale prices]"><a href="login.html"><Actinic:Variable Name="RetailCustomerMessage"/>ogin</a></span></Actinic:NOTINB2B></Actinic:PRICE_EXPLANATION>
                 </actinic:block>
                
                 <actinic:block if="%3cactinic%3avariable%20name%3d%22PriceIsEnabled%22%20%2f%3e">
                    <Actinic:PRICES PROD_REF="<actinic:variable Name="ProductID" />" RETAIL_PRICE_PROMPT="<Actinic:Variable Name="ProductPriceDescription"/>">
                    <actinic:variable name="PriceListRetail" />
                    </Actinic:PRICES>
                 </actinic:block>
        
                 <actinic:block if="%3cactinic%3avariable%20name%3d%22ProductPriceIsEnabled%22%20%2f%3e%20%3d%3d%20False">
                    <Actinic:NOTINB2B><strong><actinic:variable name="ProductPriceNotEnabledMessage" /></strong></Actinic:NOTINB2B>
                 </actinic:block>
                
                 <actinic:block if="%3cactinic%3avariable%20name%3d%22DiscountDescriptionIsShownForProducts%22%20%2f%3e">     
                    <br /><actinic:variable name="DiscountList" value="Standard Discount List" />
                 </actinic:block>
                
                 <actinic:block if="%3cactinic%3avariable%20name%3d%22IsOtherInfoPromptShown%22%20%2f%3e">
                    <br />
                    <span class="actrequired"><Actinic:Variable Name="OtherInfoPrompt"/></span><br />
                    <input type="text" name="O_<actinic:variable Name="ProductID"/>" size="40" maxlength="1000" value="" />
                 </actinic:block>
                
                 <actinic:block if="%3cactinic%3avariable%20name%3d%22IsDatePromptShown%22%20%2f%3e">
                    <br />
                    <span class="actrequired"><actinic:variable name="DatePrompt"/></span><br />
                    <actinic:variable name="DayList" /><actinic:variable name="MonthList" /><actinic:variable name="YearList" />
                 </actinic:block>
                
                 <actinic:variable name="ProductAlsoBoughtList" />
                 <actinic:variable name="ProductRelatedProductsList" />
                 <actinic:variable name="FeefoProductLogo" />
                 <actinic:variable name="FeefoProductFeedback" />
        
              </td>
        
              <td width="9%" align="right" valign="middle">
                 <actinic:block if="%3cactinic%3avariable%20name%3d%22IsQuantityPromptShown%22%20%2f%3e%20AND%20%28%3cactinic%3avariable%20name%3d%22IsOutOfStockShown%22%20%2f%3e%20%3d%3d%20FALSE%29%20AND%20%28%3cactinic%3avariable%20name%3d%22IsCatalogSuspendedShown%22%20%2f%3e%20%3d%3d%20FALSE%29" > 
                     <actinic:block if="%3cactinic%3avariable%20name%3d%22CartButtonVisibleToAllCustomers%22%20%2f%3e" >
                     <!-- This code is used when the quantity box is visible to all customers -->
                     <input type="text" name="Q_<actinic:variable Name="ProductID"/>" size="4" value="<Actinic:Variable Name="DefaultQuantity"/>" />
                     </actinic:block>
                     
                     <actinic:block if="%3cactinic%3avariable%20name%3d%22EnabledForCustomerGroupID%22%20%2f%3e%20%21%3d%20%22%22">
                        <actinic:block if="%3cactinic%3avariable%20name%3d%22ProductPriceIsEnabled%22%20%2f%3e" >
                        <!-- This code is used when the quantity box is visible to retail customers, but not all other customer groups -->
                        <Actinic:ShowForPriceSchedule Schedules="<actinic:variable name="EnabledForCustomerGroupID" />">&nbsp;
                        <input type="text" name="Q_<actinic:variable Name="ProductID"/>" size="4" value="<Actinic:Variable Name="DefaultQuantity"/>" />
                        </Actinic:ShowForPriceSchedule>
                        </actinic:block>
                        
                        <actinic:block if="%3cactinic%3avariable%20name%3d%22ProductPriceIsEnabled%22%20%2f%3e%20%3d%3d%20FALSE" >   
                        <!-- This code is used when the quantity box needs to hidden from retail customers -->
                        <Actinic:ShowForPriceSchedule Schedules="<actinic:variable name="EnabledForCustomerGroupID" />" HTML="<span class='actrequired'></span>&nbsp;<input type='text' name='Q_<actinic:variable Name="ProductID"/>' size='4' value='<Actinic:Variable Name="DefaultQuantity"/>' />"></Actinic:ShowForPriceSchedule>
                        </actinic:block>
                     </actinic:block>
                 </actinic:block>
                 
                 <actinic:block if="%3cactinic%3avariable%20name%3d%22IsQuantityPromptHidden%22%20%2f%3e">
                    <input type="hidden" name="Q_<actinic:variable Name="ProductID"/>"  value="<actinic:variable name="DefaultQuantity"/>" />
                 </actinic:block>
                 
                 <actinic:variable name="AttributeList" />
                 <actinic:variable name="ComponentList" />
                 <br /><actinic:variable name="CartError" />
                 <actinic:block if="%3cactinic%3avariable%20name%3d%22IsAddToCartButtonShown%22%20%2f%3e%20AND%20%0d%28%3cactinic%3avariable%20name%3d%22NumberAttributesInPushButtonGrid%22%20%2f%3e%20%3d%3d%200%29" >
                    <br /><actinic:variable name="AddToCartButton" />
                 </actinic:block>
                 
                 <actinic:block if="%3cactinic%3avariable%20name%3d%22IsOutOfStockShown%22%20%2f%3e">
                    <br /><br /><strong><span class="actrequired"><br /><Actinic:Variable Name="OutOfStock"/></span></strong>
                 </actinic:block>
                 
                 <actinic:block if="%3cactinic%3avariable%20name%3d%22IsCatalogSuspendedShown%22%20%2f%3e">
                    <br /><br /><strong><span class="actrequired"><Actinic:Variable Name="CatalogSuspended"/></span></strong>
                 </actinic:block>
                
              </td>
           </tr>
        </table>
        
        <table width="100%" cellspacing="0" cellpadding="1" style="border-top:dotted 1px #003399;">
          <tr>
             <td width="13%" align="left" valign="middle" style="height:26px;"><actinic:variable name="RealTimeStockDisplay" /></td>
             <td id="retailex" width="21%" align="left" valign="middle">
               RRP (Ex) <Actinic:PRICES> £<actinic:variable name="ProductPriceRaw" /></Actinic:PRICES></td>
             <td width="22%" align="left" valign="middle">
               <Actinic:PRICES>
               <actinic:block php="true">
               $rawprice = <actinic:variable name="ProductPriceRaw" selectable="false" />;
               {
               $rrpincvat = number_format(($rawprice*1.2), 2, ".", " ");
               echo "RRP (Inc) £$rrpincvat";
               }
               </actinic:block>
               </Actinic:PRICES>
             </td>
             <td width="22%" align="left" valign="middle">TRADE (ex) 
               <Actinic:PRICES PROD_REF="<actinic:variable Name="ProductID" />" RETAIL_PRICE_PROMPT="<Actinic:Variable Name="ProductPriceDescription"/>">
               <actinic:variable name="PriceListRetail" />
               </Actinic:PRICES>
             </td>
             <td width="22%" align="left" valign="middle">
             % off RRP =    
             <script>
               var tradeprice = document.getElementById('trade').innerHTML.replace(/[^\d\.]/g, '');
               var retailpriceex = document.getElementById('retailex').innerHTML.replace(/[^\d\.]/g, '');
               var tradedisc = ((retailpriceex-tradeprice)/retailpriceex)*100;
               var tradedisc = tradedisc * 10;
               var tradedisc = Math.round(tradedisc);
               var tradedisc = tradedisc / 10;
               document.write(tradedisc + '%');
             </script>      
             </td>
           </tr>
        </table>           
        		  
        </div>
        <!-- Trade End -->
        
              </td>
              
                   <td width="6" align="right">&nbsp;</td>
                   <td width="2" height="100%" align="right" bgcolor="#003399"><img src="box_line.gif" width="2" height="100%" /></td>
                  
              </tr>
        </table>
        <actinic:block if="%3cactinic%3avariable%20name%3d%22IsProductFormUsed%22%20%2f%3e">
              </form>
        </actinic:block>

        Comment


          #5
          As you have multiple products on your pages you'll have multiple instances of id="trade". Which won't work. Also, you've chosen product references that look like numbers so they may be extracted from the innerHTML. E.g. a sample live product has HTML.
          Code:
          <td id="trade" width='20%' align='right' valign='middle'>
          	<Actinic:PRICE_EXPLANATION PROD_REF="1.030" COMPONENTID=-1><Actinic:NOTINB2B><span TITLE="header=[<center>Login Required</center>] body=[Please login for wholesale prices]"><a href="login.html">Login</a></span></Actinic:NOTINB2B></Actinic:PRICE_EXPLANATION>
          	<Actinic:PRICES PROD_REF="1.030" RETAIL_PRICE_PROMPT="Price:">
          	</Actinic:PRICES>
          	<Actinic:NOTINB2B><strong></strong></Actinic:NOTINB2B>
          	<div class="feefoproductlogo"></div>
          </td>
          So instead of stripping everything that isn't 0-9 and ".", I'd suggest detecting £n.nn (watch out for embedded commas if you have prices above £999).

          And I've also no idea what that
          Code:
          TITLE="header=[<center>Login Required</center>] body=[Please login for wholesale prices]">
          Is meant to do.
          Norman - www.drillpine.biz
          Edinburgh, U K / Bitez, Turkey

          Comment


            #6
            Thanks for the help Norman. I am trying to give your suggestion a go. Where should I put the JavaScript that you say needs to run once only at bottom of page: I have tried putting it at the bottom of the section page, but can't get it to work. I have simply put var percentoff = 10; to test, so I should get inner + 10.

            The odd bit of code you mention is leftover from how I use to display or not, the tool tip discount message - I've removed it now. Thanks.

            Lee

            Comment


              #7
              Where should I put the JavaScript that you say needs to run once only at bottom of page
              Try Product List Layout / click to edit list layout settings / End of List. Put code after existing stuff.

              If you "can't get it to work" I'd need much more detail or a link to a faulty page (and login details) to help.
              Norman - www.drillpine.biz
              Edinburgh, U K / Bitez, Turkey

              Comment


                #8
                Thanks again Norman. Works perfectly - I hadn't got <Actinic:PRICES> tags around the PriceListRetail in the <td class="trade_ProductPriceRaw" field.

                I am now trying to refine the calculation bit of the script to round to 1 DP (I guess there is a batter way of doing it than I have used). And I'm not sure how javascript reacts to divide by zero - do I need to check for the case ppraw = 0?

                Code:
                      var percentoff = ((ppraw-tradeprice)/ppraw)*100;
                      var percentoff = percentoff * 10;
                      var percentoff = Math.round(percentoff);
                      var percentoff = percentoff / 10;

                Comment


                  #9
                  1. Are you trying to round to 1 decimal point or display to 1 decimal point? See http://community.sellerdeck.com/showthread.php?t=51811

                  Whoops. That one's in PHP. See this for how it works in javascript. http://stackoverflow.com/questions/4...es-no-rounding

                  2. Javascript won't like dividing by zero. Have you any zero priced products?

                  Mike
                  -----------------------------------------

                  First Tackle - Fly Fishing and Game Angling

                  -----------------------------------------

                  Comment


                    #10
                    Best to omit the entire thing if ppraw or tradeprice is zero:
                    Code:
                    var tdcells = document.getElementsByTagName('td');
                    for (var i=0; i<tdcells.length; i++)
                    	{
                    	if (tdcells[i].className.indexOf('trade_') > -1)
                    		{
                    		var ppraw = tdcells[i].className.replace(/trade_/, '');
                    		var inner = tdcells[i].innerHTML;
                    		var tradeprice = inner.replace(/[^\d\.]/g, '');
                    		if ( (ppraw != 0) && (tradeprice !=0) )
                    			{
                    			var percentoff = CALCULATE AND STRING FORMAT DISCOUNT PERCENTAGE USING ppraw and tradeprice
                    			// add the percentage off info to the innerHTML
                    			tdcells[i].innerHTML = inner + percentoff;
                    			}
                    		}
                    	}
                    And, as Mike suggests, use .toFixed(1) to get a single decimal digit accuracy.
                    Norman - www.drillpine.biz
                    Edinburgh, U K / Bitez, Turkey

                    Comment


                      #11
                      Perfect! Thanks Guys.
                      Lee

                      Comment

                      Working...
                      X