Announcement

Collapse
No announcement yet.

PHP Product list error.

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

    PHP Product list error.

    Hi all

    I was trying to count how many product items are in a section or sub-section, using the following code added to the Section - Main Product Area Layout (INNERLAYOUT)
    I added this very simple code just above "ProductLayout" in layout code.

    <actinic:block php="true">$productcount = 0;</actinic:block>

    <actinic:block type="ProductList" />
    <actinic:block php="true">$productcount++;</actinic:block>
    </actinic:block>

    <actinic:block php="true">
    echo "There are $productcount products in this section.";
    </actinic:block>

    The code works fine for sub-sections with zero or two or more products.
    But if a sub-section only has one product it echo's "There are 2 products in this section."

    So I changed Product list code to see what was going on.

    <actinic:block type="ProductList" />
    <actinic:block php="true">
    $productcount++;
    echo "$productcount found.";
    </actinic:block>
    </actinic:block>

    With zero products in a sub-section nothing is echoed (correct)
    On one Product "2 found." (wrong should be "1 found.")
    on two Products "1 found. 2 found." (correct)
    on three Products "1 found. 2 found. 3 found" (correct)
    and so on.

    Is this a programmng error, installation error or Actinic bug.

    Thanks
    Sean

    #2
    PHP variables persist as Actinic processes the site. So make sure you reinitialise $productcount at the top of every page. Best do this in the Overall Layout as it seems that variables assigned in the Start Of List entries aren't set properly (they may not be treated a globals within Start Of List).
    Norman - www.drillpine.biz
    Edinburgh, U K / Bitez, Turkey

    Comment


      #3
      I have just tried it on another installation, I had to hand, with exactly the same results.

      Using Actinic V8.5, looks like another bug to me

      Comment


        #4
        Cheers Norman

        I reinitialise $productcount just before the productlist block. I did that because Actinic should run it in one go, but maybe not.

        I just tried adding it to the top of the Main Page, just after <body onload="PreLoadImages">. But still with the same result.

        I take it that Actinic must compile the code in a strange order!?

        With that in mind I have just added code after the Productlist block code, to reinitialise $productcount=0. Still the same results.

        Off for some wall head banging.

        Sean

        Comment


          #5
          Add a line to your test code that displays the product name

          e.g.

          echo '<br /><actinic:variable name="ProductName" encoding="perl" selectable="false" />';
          Norman - www.drillpine.biz
          Edinburgh, U K / Bitez, Turkey

          Comment


            #6
            Hi Norman

            Added above code, result the same with Product Title added.

            Interesting "ProductName" doesn't exist in variables dropdown list. Exists in Help Variable ref guide.

            One thing to note. Adding

            <actinic:block php="true">echo "$productcount found.";</actinic:block>

            just before and just after <actinic:block type="ProductList" />
            the result is 0 before and 1 after. (for 1 product subsection)


            I tried to assign a PHP variable an Actinic variable value with

            $temp=<actinic:variable name="ProductName" encoding="perl" selectable="false" />;

            I got an parse error, obviously this is how not to pass Actinic variables to PHP )

            I can only assume from this Actinic must run through the ProductList code twice, only when one product avaliable. The first time it suppresses the HTML generated.

            If I could store actinic prodref variable into PHP variable or array maybe I could compare last what has been added.

            But as above code show I havn't figured that out yet. The AUG has very very little on PHP and Actinic!!!

            Why isn't there a ProductList count variable!! Or does Actinic use internally ADODB.find "SectID=" & num, 1 to generate a product list?

            Sean

            Comment


              #7
              Ok sorted assigning PHP variable from an Actinic variable. I just needed to a single quotes to Actinic Variable name

              ie

              $temp=<actinic:variable name="ProductName" encoding="perl" selectable="false" />;

              becomes

              $temp='<actinic:variable name="ProductName" encoding="perl" selectable="false" />';

              I will now play a little to see if I can get around the Product List count error.

              Comment


                #8
                $temp=<actinic:variable name="ProductName" encoding="perl" selectable="false" />;

                I got an parse error, obviously this is how not to pass Actinic variables to PHP )
                This would only work if the Actinic Variable was a True /False (1 or 0 is what's actually returned) or a numeric variable.

                If it's a text Variable it needs quoted as in my echo '<...... />'; example.

                Remember that what's actually happening is that the <actinic:variable ...> bit gets parsed before the code gets passed to PHP. It's the resulting generated text that PHP sees.

                The selectable="false" fragment is also important. Actinic generates additional code during Design Previews that will mess up your PHP. The selectable="false" sub-command tells Actinic not to do this for this instance of the Variable.

                The encoding="perl" fragment is useful when you pass an Actinic Variable to PHP as a single quoted string. E.g.

                $text = '<actinic:variable name="MyTextVar" encoding="perl" selectable="false" />;

                Now actinic will expand MyTextVar as per Perl's single quoted string rules ( ' becomes \' and \ becomes \\ )

                If we left out the encoding="perl" we'd get a PHP parse error if MyTextVar contained a single quote character. E.g. our Variable contains What's the time

                $text = 'What's the time'; // would fail - no encoding="perl"

                $text = 'What\'s the time'; // is OK - with encoding="perl"
                Norman - www.drillpine.biz
                Edinburgh, U K / Bitez, Turkey

                Comment


                  #9
                  Cheers for the insight in Actinic, that helps.

                  I found a work around for product list count error.

                  <actinic:block php="true">
                  $productcount = 0;
                  $prodref="";
                  </actinic:block>

                  <actinic:block type="ProductList" />
                  <actinic:block if="%3cactinic%3avariable%20name%3d%22IsProductVisible%22%20%2f%3e">
                  <actinic:block php="true">
                  if ($prodref<>'<actinic:variable name="ProductReference" encoding="perl" selectable="false" />'){
                  $productcount ++;
                  $prodref= '<actinic:variable name="ProductReference" encoding="perl" selectable="false" />';
                  }
                  </actinic:block>
                  </actinic:block>
                  </actinic:block>

                  <actinic:block php="true">
                  echo "There are $productcount products in this section.";
                  </actinic:block>

                  I used the product reference to check for duplicates. ok not perfect but solved the problem. Added IF (isProductVisible) Block to remove counting Fragments as products.

                  Hope that helps someone else in the future.

                  regards
                  Sean

                  Comment

                  Working...
                  X