Assign Record to Category and Manufacturer

5 posts by 3 authors in: Forums > CMS Builder
Last Post: August 9, 2013   (RSS)

By Perchpole - July 31, 2013

Hello, All -

My client has asked me to set-up a method of grouping products (records) together that I hope someone will be able to help me with.

The idea is that each record is assigned to a category - as normal - but also to a "manufacturer".

The list of manufacturers would be set up in a separate editor and one would be chosen whenever a new product is created.

When the record is displayed, I want to show a list of all the other products assigned to the same manufacturer - regardless of which category they are in.

What would be the simplest way of achieving this?

Thanks,

Perchpole

By Perchpole - August 5, 2013

Hi, Ron -

Thanks for your help.

:0)

Perchpole

By Codee - August 8, 2013

Hi Ron,

With regards to the additional products by this manufacturer listings: if there are no other products by that mfg...is an error returned or a mesg? Thnks!

By rconring - August 9, 2013

Well, not as it is.  I didn't need that in my application, but I made some changes in the code to make this happen if you need it.

I changed the viewer for related products to also filter out the detail record from related products.  Then checked for existence of any related records and if none display the "no Records" message.

<?php 
  // load record from 'products'
  list($productsRecords, $productsMetaData) = getRecords(array(
    'tableName'   => 'products',
    'where'       => whereRecordNumberInUrl(0),
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $productsRecord = @$productsRecords[0]; // get first record
  if (!$productsRecord) { dieWith404("Record not found!"); } // show error message if no record found
    
  // load records of same mfg from 'products'
  list($prodRecords, $prodMetaData) = getRecords(array(
    'tableName'   => 'products',
    'where'       => "manufacturer = $productsRecord[manufacturer] and num != $productsRecord[num]",
    // only records that match detail mfg and omit product detail record
  ));
?>

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

      <!-- If related products exist in $prodRecords viewer -->
      <?php if($prodRecords): ?>
        <h2>More Products from <?php echo $productsRecord['manufacturer:label'] ?></h2>    
          <!-- loop thru product list of same mfg -->
          <?php foreach ($prodRecords as $record): ?>
            <div class="related">
              <?php echo $record['name'].'   ' ?><br/>
              <?php echo $record['manufacturer:label'] ?>
            </div>  
          <?php endforeach ?>
      <?php else: ?>
            <?php echo "No additional Products for this manufacturer" ?>
      <?php endif ?>

 Is this what you had in mind?

Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987