LemonStand Forum: Product categorised content section - LemonStand Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Product categorised content section

#1 User is offline   liamegan 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 41
  • Joined: 13-August 10

Posted 13 August 2010 - 03:03 PM

I have a situation where I am building a store for a line of food products (sauces, spice mixes etc.) and there is a section of the website called Recipes.

Recipes need to be broken down by product (so that we can supply a menu of products and then the recipes that relate to each of those products). Ideally we would be able to select multiple products per recipe.

The catch here is that while we would like this section navigable as above in it's own right, the recipes themselves should also be accessible on the product pages themselves.

Any hints, tips and advice on getting this to work would b e greatly appreciated.

Thanks.
0

#2 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,626
  • Joined: 31-October 09

Posted 13 August 2010 - 08:04 PM

Hi!

Well, you need to develop a new module for managing recipes :-)

It seems that recipes are inked to products with the "has many" relation - one recipe can have many products assigned. You can read about creating data relations on this page: http://lemonstandapp...data_relations/

In the Administration Area products on the Create/Edit Recipe page will be presented as a checkbox list (this is the way how LemonStand displays "has many" relations), so you can select multiple products.

Then, when you have the recipes->products link configured, you can load recipes on the product details page, when you have the product object. Also, on the recipe page you can load a list of products.

Let me know if you need help with developing the module. I can create a very simple module template which will contain the recipe model. After that you will continue developing it on your own.

Thanks

#3 User is offline   liamegan 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 41
  • Joined: 13-August 10

Posted 14 August 2010 - 01:37 PM

Ok cool thanks. I was hoping something already existed, but I'm reading through this dev doc now and I have to say, it seems pretty rock solid.

I'm sure I'll have some more questions later on, but thanks for the pointer.

Cheers.
0

#4 User is offline   liamegan 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 41
  • Joined: 13-August 10

Posted 14 August 2010 - 11:19 PM

So I'm following the tutorial for creating a new module - so far great - but I've hit a problem at this step:
http://lemonstandapp...ion_area_forms/

When I hit the page in the browser I receive the following error:
"Undefined index: form_model"
Screenshot:
http://cl.ly/baf0cc88315735ef040f

Controller:
<?php
    class WickedRecipes_Posts extends Backend_Controller
    {
        public $implement = 'Db_ListBehavior, Db_FormBehavior';

        public $list_model_class = 'WickedRecipes_Post';
        public $list_record_url = null;
 
        public $list_search_enabled = true;
        public $list_search_fields = array('@title', '@description', '@content');
        public $list_search_prompt = 'find recipes by title or content';
        
        public $form_model_class = 'WickedRecipes_Post';
        public $form_redirect = null;
        
        public $form_create_title = 'New Recipe';
        public $form_edit_title = 'Edit Recipe';
        public $form_not_found_message = 'Post not found';

        public function __construct()
        {
            parent::__construct();
            $this->app_module_name = 'Recipes';
            $this->app_tab = 'wickedrecipes';
            $this->app_page = 'posts';
            
            $this->list_record_url = url('/wickedrecipes/posts/edit/');
            
            $this->form_redirect = url('/wickedrecipes/posts');
        }
        
        public function index()
        {
            $this->app_page_title = 'Entries';
        }
        
        public function edit($id)
        {
            $this->app_page_title = 'Editing Entry '.$id;
            
            $this->viewData['record_id'] = $id;
        }
    }
?>


Model
<?php
    class WickedRecipes_Post extends Db_ActiveRecord
    {
        public $table_name = 'wickedrecipes_posts';
        
        public $implement = 'Db_AutoFootprints';
        public $auto_footprints_visible = true;
        public $auto_footprints_default_invisible = false;
 
        public $has_and_belongs_to_many = array(
                'product'=>array(
                'class_name'=>'Shop_Product',
                'join_table'=>'wickedrecipes_shop_products',
                'primary_key'=>'wickedrecipes_post_is',
                'foreign_key'=>'shop_product_id'
            )
        );
            
        public function define_columns($context = null)
        {
            $this->define_column('id', '#');
            $this->define_column('title', 'Title');
            $this->define_column('description', 'Description');
            $this->define_column('content', 'Content')->invisible();
            
            $this->define_multi_relation_column('name', 'product', 'Products', "@name");
        }
        
        public function define_form_fields($context = null)
        {
            $this->add_form_field('title');
            $this->add_form_field('description');
            $this->add_form_field('name');
            $this->add_form_field('content');
        }
    }
?>


Thanks,
L
0

#5 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,626
  • Joined: 31-October 09

Posted 15 August 2010 - 01:36 AM

Hi!

Your code looks great! In the controller class you don't need to declare the edit() method. The documentation page says "The form behavior adds the edit, preview and create actions to controllers automatically. You don't need to develop these actions. But you need to provide view documents for them.".

So, you need to remove the edit() method from the controller class. But you need to create the edit.htm view document. The form behavior creates the form_model variable automatically.

I also noticed that you didn't add the product list to the form (in the define_form_fields method of the model class).

Thank you!

#6 User is offline   liamegan 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 41
  • Joined: 13-August 10

Posted 15 August 2010 - 01:59 AM

Ah thanks, that did it. Yeah I'd removed the product list definition in an effort to work out where the problem was.

All fixed now, cheers.
0

#7 User is offline   liamegan 

  • Member
  • PipPipPip
  • Group: Members
  • Posts: 41
  • Joined: 13-August 10

Posted 15 August 2010 - 07:09 PM

Thanks for your help Aleksey, I think I have it all under control now. Really really great system.

Cheers!
0

Share this topic:


Page 1 of 1

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users