83 Posts
squareweb
9 years ago
4
Topic

Hi,

How to create (x) records off content-type-B after storing content-type-A record.

Is it possible to save 3 records f.i. after saving an sealed article.

I'd like to let customers buy ticket-packages, each package contains 5, 10, 15 tickets which can be used for support.

So when a package is bought (saved in content type-A) then I'd like to auto-create 5 (10, 15) records i.e. articles of content-type-B.

Probably only with custom php and plugin?

Thanks in advance.

Mark

Get a Book for SEBLOD
9 years ago
1
Level 1

Hi,

You're right, it can be done through custom php and a 'After Store field plugin' : http://www.seblod.com/products/1854

there's a CCK php class that lets you create custom content.

The 'create' method has 3 parameters :

1st is the content type name (not title)

2nd is an array of values indexed by the Joomla object column names (#__content, #__categories or #__users)

3rd is an array of values indexed by the CCK content type column names

In this example, we just fill the basic Joomla article fields and a cck field value which would link Content A & B

This field would be configured to process a php file containing this piece of code :

<?php defined('JPATH_BASE') or die;

$app=JFactory::getApplication();

$db=JFactory::getDBO();

$content_a=new JCckContent( $config['id'] );

if ($config['isNew']) { //Content A is new

  $content_b = new JCckContent( array('joomla_article') );

  $status=$content_b->create(

    'content_type_b_name',

    array(

      'title'=> $content_a->get('title') . ' - Content B',

      'catid'=>##,

      'state'=>1,

      'language'=>'*',

      'publish_up'=>JFactory::getDate()->toSql(),

      'created_by'=>$content_a->get('created_by'),

      'access'=>$content_a->get('access')

    ),

    array(

      'content_a_id'=>$custom_view->get('id'),

      ...

    )

} else { //Content A has been updated

  //Actions on content A update

}

Olivier

8 years ago
0
Level 2

Merci beaucoup.

Juste une précision pour les débutants comme moi. Il manque la parenthèse fermante de la méthde create (après la parenthèse du dernier array.)

$status=$content_b->create(

'content_type_b_name',

array(

'title'=> $content_a->get('title') . ' - Content B',

'catid'=>##,

'state'=>1,

'language'=>'*',

'publish_up'=>JFactory::getDate()->toSql(),

'created_by'=>$content_a->get('created_by'),

'access'=>$content_a->get('access')

),

array(

'content_a_id'=>$custom_view->get('id'),

...

) )

83 Posts
squareweb
9 years ago
1
Level 1

Hi Olivier,

I've bought the plugin yesterday. I'll give it a try.

Thanks for quick response.

Mark

1283 Posts
Bucklash
9 years ago
0
Level 2

Hi folks

EDIT: I have deleted this post.


Thanks
Bucklash

Get a VIP membership