Announcement

Collapse
No announcement yet.

automatic display of price in optional components

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

    automatic display of price in optional components

    v8
    Create a new item, add an option, tick the "is optional", give it a price, displays with the tickbox, alls ok.
    whats the equivilent variable name for the actual raw price of that option, and does it have a pre-vat price display value available?

    in theory, it should start with Component??? as in ComponentDisplayLabel, but I just can't find it.

    can anyone help please.

    kev

    #2
    I can't think of a way to get a Component Price without directly querying the database which is a tricky thing to do.

    However if you associate a product with that Component, then you can use
    Code:
    <actinic:variable name="AssociatedProduct::ProductPriceRaw" />
    inside e.g. layout: Standard Component Layout.

    Since you may have some Components that don't use Associated Products it may be safer to use a blockif that tests IsUsedAssociatedProduct:
    Code:
    <actinic:block if="%3cactinic%3avariable%20name%3d%22IsUsedAssociatedProduct%22%20%2f%3e">
        <actinic:variable name="AssociatedProduct::ProductPriceRaw" />
    </actinic:block>
    Norman - www.drillpine.biz
    Edinburgh, U K / Bitez, Turkey

    Comment


      #3
      Norman,
      thanks, I was hoping there was a variable available to me (that I didn't know the name of) - seems not. and the thought of associated products just doesn't seem to hang right, so I've taken the alternative path suggested,namely direct access to the database.
      this code is for Version EIGHT - probably the only subtle change required for other versions is the small bit of code within the actinic_main.php $connect = odbc_pconnect("ActinicCatalog8","","");
      and you probably need to change the 8 to a 9 or something

      following Norman's followup posting, I've changed the code and included the ammendments as suggested to allow automatic upgrades to the next versions of actinic

      the working code/concept is as follows for anyone wanting to copy it. (perhaps a knowledgeBase addition)




      step 1.
      backup, backup again, and then back it up aonther time

      step 2.
      add a new function to the bottom of actinic_main.php - this is the main set of php functions that can then be accessed within your pages. - close down Actinic, and add the following to the bottom, before re-opening actinic.
      If it generates an error upon opening, then you've made a mistake - probably because it needs to go just above the final ?> within the actinic_main.php
      the code is as follows:
      Code:
      function GetComponentPrice($componentID, $actinicVersion) {
      	$connect = odbc_pconnect("ActinicCatalog" . $actinicVersion,"","");	
      	$query = "SELECT [nvalue2] FROM [ProductProperties] WHERE [nPropertyID] = ".$componentID;
      	$result = odbc_exec($connect, $query);
      	$resultPrice="";
      	while(odbc_fetch_row($result)){
      		$resultPrice =  odbc_result($result, 1);
      		}
              odbc_free_result($result);
      	odbc_close_all();    
      	return $resultPrice;
      	}
      step 3.
      now ammend your layout as follows:
      Code:
      <actinic:block php="true" >
      	$componentPrice = GetComponentPrice('<actinic:variable name="ComponentID" />', '<actinic:variable name="ECMajorVersion" />');
      	formattedcurrency($componentPrice/100, <actinic:variable name="CurrencyDigits" />, '<actinic:variable name="MoneyDecimalSeparator" />', '<actinic:variable name="MoneyThousandSeparator" />', '<actinic:variable name="DefaultCurrency" />');
      </actinic:block>
      thats it.




      in my particular case, I wanted the optional component price to be displayed immediately after the checkbox and displayName . so I had the following code
      Code:
      <actinic:block if="%3cactinic%3avariable%20name%3d%22IsComponentCheckboxShown%22%20%2f%3e">
         <div class="optExtras">Optional Extras</div>
          <input type="checkbox" name="<Actinic:Variable Name="UIWidgetName"/>" <actinic:block if="%3cactinic%3avariable%20name%3d%22IsSelectedByDefault%22%20%2f%3e">checked="checked"</actinic:block> />
      </actinic:block> 
      <actinic:block if="%3cactinic%3avariable%20name%3d%22IsComponentHiddenFieldIncluded%22%20%2f%3e"><input type="hidden" name="<Actinic:Variable Name="UIWidgetName"/>" value="on" /></actinic:block>
      <span id="lineUp"><Actinic:Variable Name="ComponentDisplayLabel"/> ... 
      <actinic:block php="true" >
      $componentPrice = GetComponentPrice('<actinic:variable name="ComponentID" />', '<actinic:variable name="ECMajorVersion" />');
      formattedcurrency($componentPrice/100, <actinic:variable name="CurrencyDigits" />, '<actinic:variable name="MoneyDecimalSeparator" />', '<actinic:variable name="MoneyThousandSeparator" />', '<actinic:variable name="DefaultCurrency" />');
      </actinic:block>
      </span>

      Hopefully its useful to someone

      kev

      Comment


        #4
        Note that code in actinic_main.php will be applied to all sites and will get overwritten when you update Actinic. It's also version 8 specific.

        If you want the code to survive updates, put the function GetComponentPrice into a textfile (say GetComponentPrice.php) that you save in your Site folder. Also put <?php and ?> tags around it. In your Layout code put
        Code:
        include_once 'GetComponentPrice.php';
        To avoid the Actinic version dependency, change
        Code:
        function GetComponentPrice($componentID) {
        	$connect = odbc_pconnect("ActinicCatalog8","","");
        To be
        Code:
        function GetComponentPrice($componentID, $actinicVersion) {
        	$connect = odbc_pconnect("ActinicCatalog" . $actinicVersion,"","");
        And call the code like:
        Code:
        GetComponentPrice('<actinic:variable name="ComponentID" />', '<actinic:variable name="ECMajorVersion" />')
        A final tweak would be to add GetComponentPrice.php to Design / Additional Files, to ensure that it's included in Snapshots. I don't think actinic_main.php is, which may make it tricky to move to another system.
        Norman - www.drillpine.biz
        Edinburgh, U K / Bitez, Turkey

        Comment


          #5
          Norman,
          I've also looked this morning again, seems I was on 8.0.4 and since 8.5.2 they now allow you to use siteincludes.php
          PHP Site specific library
          Designers may now add there own site wide PHP functions to be used in Actinic. If required, the file needs to be named ‘siteincludes.php’ and stored in the Site (should read sites - with an extra S on the end) folder. This file, if present, will be included in the site snapshot.

          If PHP encounters errors while parsing either actinic_main.php or siteincludes.php then the error will be written to PHPErrors.log in the sites folder.
          so I thought I'd upgrade, and guess what, just like you said, it over wrote my functions I'd just created.

          I've had to find the backup and re-instate the concept.

          I have ammended my original posting to include the code tweaks you mention.

          thanks for the clues

          kev

          Comment


            #6
            Originally posted by completerookie View Post
            Norman,
            I've also looked this morning again, seems I was on 8.0.4 and since 8.5.2 they now allow you to use siteincludes.php


            so I thought I'd upgrade, and guess what, just like you said, it over wrote my functions I'd just created.

            I've had to find the backup and re-instate the concept.

            I have ammended my original posting to include the code tweaks you mention.

            thanks for the clues

            kev
            You can also add php in layouts in the header section, that allows code to transfer through updates.

            Malcolm

            SellerDeck Accredited Partner,
            SellerDeck 2016 Extensions, and
            Custom Packages

            Comment


              #7
              Originally posted by NormanRouxel View Post
              I can't think of a way to get a Component Price without directly querying the database which is a tricky thing to do.

              However if you associate a product with that Component, then you can use
              Code:
              <actinic:variable name="AssociatedProduct::ProductPriceRaw" />
              inside e.g. layout: Standard Component Layout.

              Since you may have some Components that don't use Associated Products it may be safer to use a blockif that tests IsUsedAssociatedProduct:
              Code:
              <actinic:block if="%3cactinic%3avariable%20name%3d%22IsUsedAssociatedProduct%22%20%2f%3e">
                  <actinic:variable name="AssociatedProduct::ProductPriceRaw" />
              </actinic:block>
              We use Sellerdeck V11:
              Thanks for this idea... but... It only displays price with no VAT
              How to display prices vith and without VAT ?

              Bertrand
              "LABOR IMPROBUS OMNIA VINCIT"

              Comment


                #8
                Assuming all your products have the same tax rate:
                Code:
                <actinic:block php="true">printf("%01.2f", <actinic:variable name="AssociatedProduct::ProductPriceRaw" selectable="false" /> * 1.2);</actinic:block>
                Change the 1.2 to suit the tax rate you use. And remember you'll need to re-do it if taxes change in the future.
                Norman - www.drillpine.biz
                Edinburgh, U K / Bitez, Turkey

                Comment


                  #9
                  Wonderfull, Thanks a lot... it works fine !
                  "LABOR IMPROBUS OMNIA VINCIT"

                  Comment

                  Working...
                  X