Display price options from one multi-list with their assigned product of a different multi-list.

3 posts by 2 authors in: Forums > CMS Builder
Last Post: October 26, 2017   (RSS)

By Mikey - October 11, 2017

I have a "Product Listings" multi section editor and a "Product Pricing Options" multi section editor. In the "Product Pricing Options" I have a list field (Get options from database "value = num", "label - title") created that you can select an item from "Product Listings" and create additional pricing options for the product. The "Product Pricing Options" are connected to the products by the product num. I have the code below and it works fine on the "Product's Details Page".

  // load record from 'product_listings'
  list($product_listingsRecords, $product_listingsMetaData) = getRecords(array(
    'tableName'   => 'product_listings',
    'where'       => whereRecordNumberInUrl(0),
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $product_listingsRecord = @$product_listingsRecords[0]; // get first record
  if (!$product_listingsRecord) { dieWith404("Record not found!"); } // show error message if no record found
 
      // load record from 'additional pricing'
  list($additionalPricingRecords, $additionalPricingMetaData) = getRecords(array(
    'tableName'   => 'product_pricing_options',
    'where'         => "assign_to_product = '{$product_listingsRecord['num']}'",
    'loadUploads' => true,
    'allowSearch' => false,
  ));
  $additionalPricingRecord = @$additionalPricingRecords[0]; // get first record


    <h2><?php echo htmlspecialchars($product_listingsRecord['title']); ?></h2>
    <p><?php echo htmlspecialchars($product_listingsRecord['summary']); ?></p>
    <h4>
        Item Number: <?php echo htmlencode($product_listingsRecord['sku']) ?><br>
        Price: $<?php echo htmlencode($product_listingsRecord['price']) ?>
    </h4>
  
    <h4>Options:</h4>
    <?php foreach ($additionalPricingRecords as $record): ?>
            <?php echo htmlencode($record['title']) ?><br/>
            Description: <?php echo $record['description']; ?><br/>
            Price: $<?php echo htmlencode($record['price']) ?><br/>
    <?php endforeach ?>

What I need to do now is display the product's pricing options on a products multi-list page. I tried using the code below, but it throws an error on the "num". I guess because it's looking for a record number that doesn't exist because the page is a multi-list.

   // load records from 'product_listings'
  list($product_listingsRecords, $product_listingsMetaData) = getRecords(array(
    'tableName'   => 'product_listings',
    'loadUploads' => true,
    'allowSearch' => false,
  ));

  list($additionalPricingRecords, $additionalPricingMetaData) = getRecords(array(
    'tableName'   => 'product_pricing_options',
    'where'         => "assign_to_product = '{$product_listingsRecords['num']}'",
    'loadUploads' => true,
    'allowSearch' => false,
  ));


<?php foreach ($product_listingsRecords as $record): ?>
<a href="<?php echo $record['_link'];?>"><?php echo $record['title'] ?></a>
<?php echo htmlencode($record['content']) ?>
Item Number: <?php echo htmlencode($record['item_number_sku']) ?><br>
Base Price: $<?php echo htmlencode($record['price']) ?>

    <h4>Options:</h4>
    <?php foreach ($additionalPricingRecords as $recordAddition): ?>
            <?php echo htmlencode($recordAddition['title']) ?><br/>
            Description: <?php echo $recordAddition['description']; ?><br/>
            Price: $<?php echo htmlencode($recordAddition['price']) ?><br/>
    <?php endforeach ?>

Anyone have any suggestions on how to get the price options from the "product_pricing_options" and display them with their perspective products?

Thanks Zicky

By Mikey - October 26, 2017

Hey Dave,

Thanks for the guidance - that did the trick.