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 rconring - July 31, 2013 - edited: July 31, 2013

I would set up a second product (list) viewer on the detail page and use the manufacturer variable from the first viewer record to limit the second list to the product manufacturer in the first.  That would list all other products by that manufacturer on the detail page.

Here is some sample code I copied from one of my sites:

Viewers on detail page:

  // 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'
    $thismfg = $productsRecord['manufacturer'];  // assign product mfg to a simple variable
  list($prodRecords, $prodMetaData) = getRecords(array(
    'tableName'   => 'products',
    'where'                => "manufacturer = '$thismfg'", // only records that match detail mfg
  ));

Display the related products from same mfg and skip detail product.


  <!-- loop thru product list of same mfg -->
  <?php foreach ($prodRecords as $record): ?>
    <!-- if not same record as detail record -->
    <?php if($record['num'] != $productsRecord['num']): ?>
      <div class="prod-box">                        
        <?php echo $record['name'] ?><br/>
      </div>
    <?php endif ?>
  <?php endforeach ?>

Hope that helps.

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

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!