[SOLVED] Product price list item ref null
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
-
- Posts: 72
- Joined: 22 Mar 2021, 16:56
[SOLVED] Product price list item ref null
Hello,
I am trying to do an initial setup of prices specific for groups.
In simple terms I am creating a price, attaching a group to that price and attaching the price to the product.
I have x amount of groups, and each group has an assigned discount.
Ive got a command setup that fetches products along with the price domains.
Im iterating of these products and getting the list items for the price domain.
For each of this items, I am creating price * groups.
For brevity I have excluded a lot of boiler, but you can hopefully get the gist...
This goes some way to doing what I intend, but when I make a fresh request for the list items belonging to the product, only the original have refs, ie. getRefItem() returns null for the x3 prices I just created. In the back office, they appear OK and have the attached list items.
If we take the orignal list, which returns a map and call getRefItem
Is this correct, am I barking up the wrong tree? I would have assumed ALL prices should have refItems, which means something I am doing is failing to create the necessary relationship.
Im hoping someone might see what I am doing wrong...
Thanks,
* I have installed the customer/group extension, although should not be relevant as the question is more around manager functionality
I am trying to do an initial setup of prices specific for groups.
In simple terms I am creating a price, attaching a group to that price and attaching the price to the product.
I have x amount of groups, and each group has an assigned discount.
Ive got a command setup that fetches products along with the price domains.
Im iterating of these products and getting the list items for the price domain.
For each of this items, I am creating price * groups.
For brevity I have excluded a lot of boiler, but you can hopefully get the gist...
Code: Select all
$listItems = $productItem->getListItems('price');
foreach ($listItems as $item) {
foreach ($customerGroups as $customerGroup) {
$refItem = $item->getRefItem();
$rebateValue = $refItem->getValue() * ($this->groupDiscounts[$customerGroup->getCode()] / 100);
$priceValue = $refItem->getValue() - $rebateValue;
$list = [
'price.value' => $priceValue,
'price.lists.type' => 'default',
'rewardvalue' => $priceValue * 100,
'price.rebate' => $rebateValue,
'price.currencyid' => $refItem->getCurrencyId(),
'price.taxrates' => $refItem->getTaxRates(),
];
$listItem = $productManager->createListItem()->fromArray($list);
$priceItem = $priceManager->create()->fromArray($list);
$productItem->addListItem('price', $listItem, $priceItem);
$priceItem->addListItem('customer/group', $priceManager->createListItem(), $customerGroup);
}
}
$productManager->save($productItem);
If we take the orignal list, which returns a map and call getRefItem
Code: Select all
$items = $productItem->getListItems('price')->getRefItem();
[
737 => null
738 => null
739 => null
735 => Aimeos\MShop\Price\Item\ItemStandard
]
Im hoping someone might see what I am doing wrong...
Thanks,
* I have installed the customer/group extension, although should not be relevant as the question is more around manager functionality
Last edited by createanet on 15 Nov 2021, 09:56, edited 1 time in total.
-
- Posts: 72
- Joined: 22 Mar 2021, 16:56
Re: Product price list item ref null
Seems like the issue is related to adding the list item to the price before adding to product, here:
When I remove this, and request product ref items I get all as expected, ie. no null values as I described previously.
Is there another way for me build these relations before the price exists? My approach seems to follow the advice given below:
Customer Group Specific Prizes
Thanks,
Code: Select all
$priceItem->addListItem('customer/group', $priceManager->createListItem(), $customerGroup);
Is there another way for me build these relations before the price exists? My approach seems to follow the advice given below:
Customer Group Specific Prizes
Thanks,
Re: Product price list item ref null
There can be two reasons why no referenced item is available when loading the data:
- Your $customerGroup variable is NULL when calling addListItems()
- The record referenced by $customerGroup is not available any more because it may have been deleted
Check the "mshop_price_list" table if the "refid" contains values and if they match the "id" column in the "mshop_customer_group" table
- Your $customerGroup variable is NULL when calling addListItems()
- The record referenced by $customerGroup is not available any more because it may have been deleted
Check the "mshop_price_list" table if the "refid" contains values and if they match the "id" column in the "mshop_customer_group" table
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
-
- Posts: 72
- Joined: 22 Mar 2021, 16:56
Re: Product price list item ref null
Thanks for the pointers...
With that said, when checking the "mshop_product_list", the refids match those of the "mshop_price" and parentid listed on the "mshop_price_list".
I might just scaffold a new site on my localhost with a fresh extension and no changes to be double sure its not something I have changed that might be causing this.
Thanks again
Ive logged this, and can confirm the value is never null and the expected group id is returned1. Your $customerGroup variable is NULL when calling addListItems()
Im making the requests for the referenced items immediately after the execution of storing. If something is being removed, its somewhere else in the system doing it perhaps?2. The record referenced by $customerGroup is not available any more because it may have been deleted
This as far as I had got to previously and what is odd, is that all the records that should exist, exist here, and the refid is that if the mshop_customer_group. Everything checks out, however the issue as far as I can see isn't with the relation of the group and price, but the price to the product as its the products price listems that have null refs.Check the "mshop_price_list" table if the "refid" contains values and if they match the "id" column in the "mshop_customer_group" table
With that said, when checking the "mshop_product_list", the refids match those of the "mshop_price" and parentid listed on the "mshop_price_list".
I might just scaffold a new site on my localhost with a fresh extension and no changes to be double sure its not something I have changed that might be causing this.
Thanks again
-
- Posts: 72
- Joined: 22 Mar 2021, 16:56
Re: Product price list item ref null
...I have just noticed that when I remove the records from the "mshop_price_list" for the "customer/group" domain the price list references return as expected - this isn't what I want, but it does illustrate further that the issue is related to the price list items and not the product list items.
Re: Product price list item ref null
If the stored data is OK, it's a fetch issue most likely because customer/group items apply restrictions on what is available. Try this instead:
Code: Select all
$items = $productItem->getListItems('price', null, null, false)->getRefItem();
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
-
- Posts: 72
- Joined: 22 Mar 2021, 16:56
Re: Product price list item ref null
Dam! I really was thinking that was going to be it Unfortunately not, the results are the same.
-
- Posts: 72
- Joined: 22 Mar 2021, 16:56
Re: Product price list item ref null
Morning,
I've setup a fresh environment scaffolded with the demo data with zero extensions.
Everything works as expected. I copy over the customer/group extension from Aimeos GmbH...bingo, null references.
I guess as this a premium extension it is therefore not supported by OS I will need to chase up with them directly?
If there is anything in the meantime that is glaringly obvious I have missed and failed to have done please shoot me a message.
Thanks for your time on this,
Mart
I've setup a fresh environment scaffolded with the demo data with zero extensions.
Everything works as expected. I copy over the customer/group extension from Aimeos GmbH...bingo, null references.
I guess as this a premium extension it is therefore not supported by OS I will need to chase up with them directly?
If there is anything in the meantime that is glaringly obvious I have missed and failed to have done please shoot me a message.
Thanks for your time on this,
Mart
Re: Product price list item ref null
Ask the folks from the Aimeos company where you've bought the extension, maybe they know more.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
-
- Posts: 72
- Joined: 22 Mar 2021, 16:56
Re: Product price list item ref null
For anyone else stumbling upon this, the issue appeared to be due to configuration. There is an option that allows you to retrieve all items but without active status.
I put this under the "command" config key in my shop.php configuration.
It was also necessary for me adjust my context by passing the type argument in order to load the specific configuration settings under "command" described above eg.
I put this under the "command" config key in my shop.php configuration.
Code: Select all
mshop/common/manager/all-items = true
Code: Select all
$context = app('aimeos.context')->get(true, 'command');