How to get the value of entitties.

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
bharti8800
Posts: 8
Joined: 05 Jul 2018, 05:02

How to get the value of entitties.

Post by bharti8800 » 12 Jul 2018, 04:56

Sorry if this question sounds stupid but i need some help.
So, this is my controller code:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ProductsController extends Controller
{
public function index()
{
$context = app( '\Aimeos\Shop\Base\Context' )->get();
$manager = \Aimeos\MShop\Factory::createManager( $context, 'product' );
$search = $manager->createSearch(true);
$expr = array(
$search->compare( '=~', 'product.code', 'demo-' ),
$search->getConditions(),
);
$search->setConditions( $search->combine( '&&', $expr ));
$search->setSortations( array( $search->sort( '+', 'product.id' )));
$search->setSlice( 0, 5 );

$total = 0;
$result = $manager->searchItems( $search, array( 'text' ), $total );

print_r($result);
$x=array();
foreach($result as $id => $item ) {

//???????How do i access Product label. I know I will get an object result with all the data. I can access the product id by $id. But how to access the product label,code,price etc.
}
}
}
I know this is a stupid question. Please help me...

bharti8800
Posts: 8
Joined: 05 Jul 2018, 05:02

Re: How to get the value of entitties.

Post by bharti8800 » 12 Jul 2018, 07:07

Also how to get the value of price. i dont see any price in the return object?
Do we have to add something while creating the manager?

User avatar
aimeos
Administrator
Posts: 7866
Joined: 01 Jan 1970, 00:00

Re: How to get the value of entitties.

Post by aimeos » 14 Jul 2018, 08:06

Please have a look at the API: https://aimeos.org/api/latest/class-Aim ... Iface.html

The product item has a method getLabel() and getName() as well as getRefItems(). Using the later one, you can get the prices, media, attributes, etc. if you add the required domain to the second parameter of searchItems():

Code: Select all

$items = $manager->searchItems( $criteria, ['price', 'media', 'attribute' /* , ... */ );
foreach( $items as $item ) {
  $item->getRefItems( 'price' /* ... */ );
}
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

bharti8800
Posts: 8
Joined: 05 Jul 2018, 05:02

Re: How to get the value of entitties.

Post by bharti8800 » 15 Jul 2018, 08:57

ok so i am able to fetch everything. Just 1 more problem.

How to get the currency symbol displayed????
For USD- $
is there a function for that.??

User avatar
aimeos
Administrator
Posts: 7866
Joined: 01 Jan 1970, 00:00

Re: How to get the value of entitties.

Post by aimeos » 16 Jul 2018, 17:17

Use this code:

Code: Select all

$this->getContext()->getI18n()->dt( 'currency', 'EUR' );
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply