Jump to content
Latest News: (loading..)
Gyakutsuki

Tuto Display a new page with APP

Recommended Posts

@Frankl and the communty has created a great example about APP. But this example does'nt have elements to create a page in front office.

This tuto resolve this point. You will the base to develop you own page

We want to create a new enhanced contact us page for example
This example don't give you all the code about the admin, classes .... Just the necessary to create a catalog page
Below you will find all  the code to start correctly ? After you must complete the elements by your own code

Note :
In App you can :
Create page In admin
Create page in Shop
Add content in Shop (header / content / footer)
Add Hook inside a page (like action, save, delete, insert, update)
Add module like order total, payment, shipping ...

You can not :
Create a boxe (I tried with no success) : use the default osc approach
Create a header_tag : use the default osc approach

Go back to our code !

Step one

oscommerce.json add Shop Element

Info&Contact will be your link to access via the catalog
Sites\\Shop\\Pages\\Manager is the location about the files and process

 "routes": {
   "Admin":	"Sites\\Admin\\Pages\\Home",
   "Shop": {
     "Info&Contact": "Sites\\Shop\\Pages\\Manager"
   }
 }
Step 2

Create your directories
Apps
-Communication
--Manager
---languages
----- english
------- Sites
---------Shop
----------Manager
---Sites
-----Shop
------Pages
-------Manager
--------Actions
----------Contact
--------templates

Step 3

Now in directories languages/english/...../Manager create contact.txt
add 
heading_title = Contact US

Step 4

Now in directories Sites/Shop/Pages/Manager
create a file Manager.php
Add

  namespace OSC\Apps\Communication\Manager\Sites\Shop\Pages\Manager;

  use OSC\OM\Registry;

  use OSC\Apps\Communication\Manager\Manager as ManagerAPP;

  class Manager extends \OSC\OM\PagesAbstract {
    public $app;

    protected function init()  {

      $OSCOM_Manager = new ManagerAPP();
      Registry::set('ManagerAPP', $OSCOM_Manager);

      $this->app = Registry::get('Manager');

      $this->app->loadDefinitions('Sites/Shop/main'); // not necessary
    }
  }

Step 5
Now in directories Sites/Shop/Pages/Manager/Actions
create a file Contact.php
Add

  namespace OSC\Apps\Communication\Manager\Sites\Shop\Pages\Manager\Actions;

  use OSC\OM\OSCOM;
  use OSC\OM\Registry;
  use OSC\OM\HTML;

  class Contact extends \OSC\OM\PagesActionsAbstract {

     public function execute() {
      global $breadcrumb, $OSCOM_Manager;

      $OSCOM_Manager = Registry::get('Manager');

// display or not the page (admin action)
      if (!defined('OSC_APP_MANAGER_STATUS') || !in_array(OSC_APP_MANAGER_STATUS, [
          '1',
          '0'
        ])) {
        return false;
      }

      $this->page->setFile('contact.php');
      $this->page->data['action'] = 'Contact';

//language
      $OSCOM_Manager->loadDefinitions('Sites/Shop/Manager/contact');

      $breadcrumb->add(OSCOM_Manager->getDef('navbar_title'), OSCOM_Manager->link('index.php', 'Info&Contact'));
    }
  }

Step 6

Now in directories Sites/Shop/Pages/Manager/Actions/Contact
create a file Process.php
Add

  namespace OSC\Apps\Communication\Manager\Sites\Shop\Pages\Manager\Actions\Contact;

  use OSC\OM\Registry;

  class Process extends \OSC\OM\PagesActionsAbstract  {

    public function execute()  {
     $OSCOM_Manager = Registry::get('Manager');


	------- your code to manage the process about the form -----

// Redirect on other page
       $OSCOM_Manager->redirect('index.php', 'Info&Contact&Success');
    }
  }

 

Step 7

Now in directories Sites/Shop/Pages/Manager/templates
create a file contact.php
Add

<?php
  use OSC\OM\OSCOM;
  use OSC\OM\Registry;
  use OSC\OM\HTML;
?>

  <div class="page-header">
    <h1><?php echo $OSCOM_PageManager->getDef('heading_title'); ?></h1>
  </div>
<?php echo HTML::form('contact', OSCOM::link('index.php', 'Info&Contact&Process'), 'post', 'enctype="multipart/form-data"',  ['tokenize' => true]);  ?>

  ---- you can continue with your code ----


Step 8

Now to access at your page : http://www.mysite/catalog/index.php?Info&Contact

 

 



Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

Tuto for 2.4 :
- How to Display a new page with app
- How to make Header Tags under app APP
- How to make a
boostrap modal with external element
 

 

Share this post


Link to post
Share on other sites

Erratum :

<?php echo HTML::form('contact', OSCOM::link('index.php', 'Info&Contact&Process'), 'post', 'enctype="multipart/form-data"',  ['tokenize' => true]);  ?>

by

<?php echo HTML::form('contact', $OSCOM_Manager->link('index.php&Info&Contact&Process'), 'post', 'enctype="multipart/form-data"',  ['tokenize' => true]);  ?>

If an administrator can change inside the first. it will be cool.



Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

Tuto for 2.4 :
- How to Display a new page with app
- How to make Header Tags under app APP
- How to make a
boostrap modal with external element
 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×