[SOLVED] Product price list item ref null

How to configure and adapt Aimeos based shops as developer
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!
createanet
Posts: 72
Joined: 22 Mar 2021, 16:56

[SOLVED] Product price list item ref null

Post by createanet » 12 Nov 2021, 14:19

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...

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);

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

Code: Select all


$items = $productItem->getListItems('price')->getRefItem();

[
    737 => null
    738 => null
    739 => null
    735 => Aimeos\MShop\Price\Item\ItemStandard
]

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
Last edited by createanet on 15 Nov 2021, 09:56, edited 1 time in total.

createanet
Posts: 72
Joined: 22 Mar 2021, 16:56

Re: Product price list item ref null

Post by createanet » 13 Nov 2021, 17:28

Seems like the issue is related to adding the list item to the price before adding to product, here:

Code: Select all

$priceItem->addListItem('customer/group', $priceManager->createListItem(), $customerGroup);
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,

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

Re: Product price list item ref null

Post by aimeos » 14 Nov 2021, 09:45

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
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

createanet
Posts: 72
Joined: 22 Mar 2021, 16:56

Re: Product price list item ref null

Post by createanet » 14 Nov 2021, 14:48

Thanks for the pointers...
1. Your $customerGroup variable is NULL when calling addListItems()
Ive logged this, and can confirm the value is never null and the expected group id is returned
2. The record referenced by $customerGroup is not available any more because it may have been deleted
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?
Check the "mshop_price_list" table if the "refid" contains values and if they match the "id" column in the "mshop_customer_group" table
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.

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

createanet
Posts: 72
Joined: 22 Mar 2021, 16:56

Re: Product price list item ref null

Post by createanet » 14 Nov 2021, 14:55

...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.

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

Re: Product price list item ref null

Post by aimeos » 14 Nov 2021, 15:03

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, Image give us a star

createanet
Posts: 72
Joined: 22 Mar 2021, 16:56

Re: Product price list item ref null

Post by createanet » 14 Nov 2021, 16:08

Dam! I really was thinking that was going to be it :) Unfortunately not, the results are the same.

createanet
Posts: 72
Joined: 22 Mar 2021, 16:56

Re: Product price list item ref null

Post by createanet » 15 Nov 2021, 08:26

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

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

Re: Product price list item ref null

Post by aimeos » 15 Nov 2021, 08:35

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, Image give us a star

createanet
Posts: 72
Joined: 22 Mar 2021, 16:56

Re: Product price list item ref null

Post by createanet » 15 Nov 2021, 09:56

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.

Code: Select all

mshop/common/manager/all-items = true
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.

Code: Select all

$context = app('aimeos.context')->get(true, 'command');

Post Reply