Help for integrating the Laravel package
Forum rules: Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
#2515 by aimeos
19 Feb 2016, 09:49
Chaeril wrote:I keep getting error 'Class 'MShop_Factory' not found' is it changed in ~2016 or i missed something?
is it \Aimeos\MShop\Factory::createManager ?


Yes, it is. The code base has been rewritten to PSR-4 compliance (namespaces) and all former class names are now prefixed by "\Aimeos\" and underscores (_) have been replaced by backslashes (\). A full list of breaking changes is available in the developer section: https://aimeos.org/docs/Developers/Changelog
#2521 by Chaeril
21 Feb 2016, 10:45
1. if i want to find stock and / or media for product, do i need to set up another manager and submanager search?

Code: Select all$manager = \Aimeos\MShop\Factory::createManager($context, 'product');
$search = $manager->createSearch();
$getSubManager = $manager->getSubManager('stock');
$sub_search = $getSubManager->createSearch();

...

$media = \Aimeos\MShop\Factory::createManager($context, 'media');
$s_media = $media->createSearch();



or there is another preferred way?.
2. When do i need to use getResourceType() and getSearchAttributes();
ResourceType seems to return an array which i can loop inside createManager () although it seems to be a bad way.
still not sure with SearchAttributes.

Regards
#2522 by aimeos
21 Feb 2016, 11:19
Media items (as well as attributes, texts, prices, etc.) are associated via the list tables. The easiest way to fetch them is along with the product item:
Code: Select all$item = $manager->getItem( '<id>', array( 'media', ...) );
$items = $manager->searchItems( $search, array( 'media', 'text', 'attribute', 'price', ... ) );

Afterwards, they are available via getRefItems():
Code: Select all$mediaItems = $item->getRefItems( 'media' [, '<media type>'] [, '<list type>'] );

More information about this methods is available in the API docs:
https://aimeos.org/api/2016/class-Aimeos.MShop.Product.Item.Iface.html
https://aimeos.org/api/2016/class-Aimeos.MShop.Common.Item.ListRef.Iface.html


You can create the submanager for retrieving stock levels with the factory too:
Code: Select all$manager = \Aimeos\MShop\Factory::createManager($context, 'product/stock');


getSearchAttributes() and getResourceType() are available to determine the search keys and resources automatically. Normally, you don't need to call them.
#2596 by Chaeril
08 Mar 2016, 12:08
Code: Select all$json = null;
    $items = $manager->searchItems($search, array('media', 'text', 'attribute', 'price'));
    foreach ($items as $id => $item) {
      $item = $manager->getItem($id, array('media', 'text', 'attribute', 'price'));
      $temp = $item->toArray();
      $temp['text'] = $item->getRefItems('text');
      $temp['media'] = $item->getRefItems('media');
      $temp['attribute'] = $item->getRefItems('attribute');
      $temp['price'] = $item->getRefItems('price');
      $json[] = $temp;
    }


i get json response something like
[0] -> ... -> [media] -> [29] -> position -> 0
i found that 29 is the id of media attached to item, should i use another manager to find preview url, or file url.
#2599 by aimeos
08 Mar 2016, 12:38
No, but you should use the toArray() method for each item to get the key/value pairs suitable for json_encode:

Code: Select all$json = array();
$items = $manager->searchItems($search, array('media', 'text', 'attribute', 'price'));

foreach ($item as $id => $item) {
    $temp = $item->toArray();
    foreach ($item->getRefItems() as $domain => $list) {
        foreach ($list as $refId => $refItem) {
            $temp[$domain][$refId] = $refItem->toArray();
        }
    }
    $json[] = $temp;
}


More information about getRefItems() and toArray():
https://aimeos.org/api/latest/class-Aimeos.MShop.Common.Item.ListRef.Iface.html
https://aimeos.org/api/latest/class-Aimeos.MShop.Common.Item.Iface.html#_toArray
#2631 by Chaeril
19 Mar 2016, 14:14
Hi,
i am stuck with creating order, from what i understand i need to create 3 manager for each of order, order/base, and order/base/product. then save order/base, get last id and save the rest of data using .baseid
is there a transactional way to do this?
#2633 by aimeos
20 Mar 2016, 15:40
Chaeril wrote:i am stuck with creating order, from what i understand i need to create 3 manager for each of order, order/base, and order/base/product. then save order/base, get last id and save the rest of data using .baseid
is there a transactional way to do this?


You only need the order and order/base manager. The item created by an order/base manager is exactly the basket of a customer and you can save it by calling the store() method:
Code: Select all$manager = \Aimeos\MShop\Factory::createManager( $context, 'order' );
$baseManager = \Aimeos\MShop\Factory::createManager( $context, 'order/base' );

$order = $manager->createItem();
$basket = $baseManager->createItem();
// ... add something to the basket ...

$manager->begin();
$baseManager->store( $basket );
$order->setBaseId( $basket->getId() );
$manager->saveItem( $order );
$manager->commit(); // or rollback()


For more information about the methods, please have a look into the API docs:
https://aimeos.org/api/latest/namespace-Aimeos.MShop.Order.Manager.html