Jump to content

Extenrnal API: Get product by name


DigItalWarrior

Recommended Posts

Hi DigitalWarrior,

 

You could try this by saving it in your hooks folder and naming as myproducts.php, changing the case, info sections to your product info and removing my notes.

I haven't tested it but is should work. Hopefully I've understood you correctly to what you are after. :idea:

 

<?php

add_hook( 'ClientAreaPage', 1, function( $vars ) {

   $user   =   Menu :: context( 'client' );
   $data   =   array( 'showproductdata' => false );

   if (! $user ) return $data;

   $products = localAPI(
       'getclientsproducts',
       array(
           'clientid' => $user->getAttribute( 'id' ),
       ),
       'admin' );


   if (! $products || $products['result'] != 'success' || $products['totalresults'] == 0 || count( $products['products'] ) == 0 ) return $data;

   $data['showproductdata']    =   true;
   $product    =   $products['products']['product'][0];
   $info       =   null;
   $title      =   $product['translated_name'];

   switch( $product['pid'] ) :
   case '1' : //change to the 1st product id
       $info = 'productname1'; //change to the product name
       break;
   case '2' : //change to the 2nd product id
       $info = 'productname2'; //change to the product name
       break;
case '3' : //change to the 3rd product id
       $info = 'productname3'; //change to the product name
       break;

   endswitch;
   $data['myproduct']  =   array( 'info' => $info, 'title' => $title);

   return $data;




});

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated