Page 1 of 2

Admin rebuild : getting/creating/updating data

Posted: 15 Jun 2015, 14:37
by Yvler
Hi

As I told in another post, we're trying to rewrite the admin panel.
Is there an easy way (à la Laravel way) to receive a list (for example of products, categories, ...) of items?
Is there another way to save and update them, or create them? :) Or do we just do the standard Laravel stuff and write to the database?

Re: Admin rebuild : getting/creating/updating data

Posted: 15 Jun 2015, 16:16
by aimeos
Yvler wrote:As I told in another post, we're trying to rewrite the admin panel.
Offering an admin interface suited for the specific needs is always a good thing. Our plan is still to offer a REST interface to ease that task.
Yvler wrote: Is there an easy way (à la Laravel way) to receive a list (for example of products, categories, ...) of items?
Is there another way to save and update them, or create them? :) Or do we just do the standard Laravel stuff and write to the database?
The principles are more or less similar but Aimeos provides a much better suited interface tailored for e-commerce applications to the data than just accessing the records. Unfortunately, tutorials for this are still missing but the methods are fully documented in the source code.

In Aimeos managers are responsible for creating, saving, deleting and searching items. The items are more or less containers for the records with a bit intelligence while the managers know how to create and handle them. Each domain (e.g. catalog, product, text, attribute, etc.) has its own manager (maybe with sub-managers) and items. As a rule of thumb, each table in the database is governed by a manager or sub-manager.

All managers share a common interface:
- createItem()
- saveItem()
- deleteItem()
- searchitems()

searchItems() is the most powerful method and I have to explain it a bit more. You can add condition and sorting rules for each search as well as the domains associated items should be fetched too. For example:

Code: Select all

$context = app( '\Aimeos\Shop\Base\Context' )->get(); // necessary context with required depencencies
$manager = MShop_Factory::createManager( $context, 'product' ); // 'product/list' would return the product list sub-manager

$search = $manager->createSearch(true);
$expr = array(
  $search->compare( '=~', 'product.code', 'demo-' );
  $search->compare( '==', 'product.list.domain', 'text' );
  $search->compare( '>=', 'product.list.datestart', '2000-01-01 00:00:00' );
  $search->getConditions(),
);
$search->setConditions( $search->combine( '&&', $expr ); // AND operator, || -> OR operator
$search->setSortations( array( $search->sort( '+', 'product.id' ); // + -> ascending, - -> descending
$search->setSlice( 10, 50 ); // start at position 10, 50 entries

$total = 0;
$result = $manager->searchItems( $search, array( 'text' ), $total ); // last two parameters are optional
This would fetch the product items whose code starts with "demo-" and which have at least one text item associated that is available after year 2000. The are ordered by product ID and the items at position 10 to 60 are returned which the associated text items available via "$item->getRefItem( 'text', ... );". The $total parameter contains the number of total items that are available for that search.

The list of conditions is described in the Wiki: http://aimeos.org/docs/Developers/Condi ... _searching
How to fetch bunches of items efficiently is also described there: http://aimeos.org/docs/Developers/Fetch ... in_bunches
The available search keys for each manager are described in the managers, e.g. for the product manager: https://github.com/aimeos/arcavias-core ... efault.php

For the categories, the same principles apply but the catalog is a tree so it contains an addition method getTree() that returns a tree of nodes independent of how the tree is stored in the database.

What else do you need to know?

Re: Admin rebuild : getting/creating/updating data

Posted: 15 Jun 2015, 16:30
by aimeos
One thing more:
There's a database entity relationship model available for a better understanding of the inner details
http://aimeos.org/docs/Developers#Library

Re: Admin rebuild : getting/creating/updating data

Posted: 16 Jun 2015, 09:29
by Yvler
We're trying to use that code in our Controller class in app/Http/Controllers/ProductController.php
But we're not getting it working :/

Which namespaces/implements do we have to do?
We're used to the Laravel code and we're not seeing the wood for the trees...

Do we need to make an extension? And if so, is it possible to provide us a simple example from which we can start?
This is the code we've had so far:

Code: Select all

<?php namespace App\Http\Controllers\Admin;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Barryvdh\Debugbar\Controllers\BaseController;
use Illuminate\Auth\Guard;
use App\Models;

use Illuminate\Http\Request;
use MyProject\Proxies\__CG__\OtherProject\Proxies\__CG__\stdClass;

class CategoryController extends Controller implements \MShop_Product_Manager_Interface{

    private $_manager = null;
    private $_context = null;
    /**

     */
    public function __construct()
    {
        $context = app( '\Aimeos\Shop\Base\Context' )->get();


        $this->_manager = \MShop_Catalog_Manager_Factory::createManager( $context );
        $this->_context = $context;
    }

Sorry for all these questions by the way..

Re: Admin rebuild : getting/creating/updating data

Posted: 16 Jun 2015, 09:48
by aimeos
Actually, it's very simple. Implement a basic Laravel controller (http://laravel.com/docs/5.1/controllers ... ontrollers) and in the actions, get the Aimeos context, create the manager you need and hand over the data you've received from the manager (or save/delete items using the managers):

Code: Select all

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

class CategoryController extends Controller
{
    public function getTree()
    {
        $context = app( '\Aimeos\Shop\Base\Context' )->get();
        $manager = \MShop_Factory::createManager( $context, 'catalog' );

        // 'mypackage.mytemplate' must be adapted to your application
        return view('mypackage.mytemplate', ['tree' => $manager->getTree()]);
    }
}

Re: Admin rebuild : getting/creating/updating data

Posted: 22 Jun 2015, 20:59
by aimeos
We've written some documentation that explains this in more detail and in different environments:
http://aimeos.org/docs/Laravel/Extend_A ... os_objects

Re: Admin rebuild : getting/creating/updating data

Posted: 23 Jun 2015, 12:19
by Yvler
Soooo...
I've added a product with the product manager
used the stock submanager to add the stock
created a new manager to add a price
added the price with a list submanager to the product.. also aded the description and meta data with this submanager.
and finally added the product to the catalog with a catalog/list manager

Everything seems to be added to the database, but I can't see the product on the homepage or under the categories..
Is there a cache I need to clear?
I already tried "\MShop_Factory::clear();" but that doesn't seem to work.

I do see this product when I surf to it directly (with the ID)


PS. There's a bug in the rebate percentage calculation. I added a price of 100 with a rebate of 10 and the rebate percentage displaying is 9%

Re: Admin rebuild : getting/creating/updating data

Posted: 23 Jun 2015, 12:35
by aimeos
Yvler wrote: Everything seems to be added to the database, but I can't see the product on the homepage or under the categories..
Is there a cache I need to clear?
I already tried "\MShop_Factory::clear();" but that doesn't seem to work.
I do see this product when I surf to it directly (with the ID)
Almost done. There are two further things you need to do:
- Create a catalog index manager and pass the product to the rebuildIndex() method to update the catalog index (example: https://github.com/aimeos/arcavias-core ... lt.php#L62)
- Clear the content cache for the category you've added the product to (example: https://github.com/aimeos/arcavias-core ... t.php#L263)

Re: Admin rebuild : getting/creating/updating data

Posted: 23 Jun 2015, 12:40
by aimeos
Yvler wrote:There's a bug in the rebate percentage calculation. I added a price of 100 with a rebate of 10 and the rebate percentage displaying is 9%
This is a common mistake in thinking. The price is the current value, the rebate is the amount the original price was reduced by, so
- current: 100
- rebate: 10
- original: 110
-> 10 * 100 / 110 = 9%
Thus, the original price was reduced by 9% compared to the current price :-)

Re: Admin rebuild : getting/creating/updating data

Posted: 19 Feb 2016, 05:16
by Chaeril
Hi,
I keep getting error 'Class 'MShop_Factory' not found' is it changed in ~2016 or i missed something?

edit:
is it \Aimeos\MShop\Factory::createManager ?