Pubilc Rebate Price in Basket

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!
nora1984antal
Posts: 4
Joined: 28 Sep 2016, 12:46

Pubilc Rebate Price in Basket

Post by nora1984antal » 10 Oct 2016, 08:36

Hi aimeos,

we have a problem with prices in the basket, so we need help.

We would like to use $product->getPrice() and we see that the rebate price is in the protected attributes, but we would like to use rebate price as a public attribute.
In this file dumped the $product->getPrice() \ext\ai-client-html\client\html\templates\common\summary\detail-body-default.php
Image

Please, help us, where can we do it.

Used: the last aimeos, laravel5.1, php 5.6, Linux

Thank you

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

Re: Pubilc Rebate Price in Basket

Post by aimeos » 11 Oct 2016, 17:37

The price item also has a method getRebate() where you can retrieve the rebate value from. Also all other properties can be retrieved by their respective get*() method: https://aimeos.org/api/latest/class-Aim ... Iface.html
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Pejka
Posts: 17
Joined: 24 Oct 2016, 11:04

Re: Pubilc Rebate Price in Basket

Post by Pejka » 14 Nov 2016, 09:33

The problem is not even really with the rebate value being protected, the problem is that a Price object holds 2 "values", which are different properties that actually share the same name, and there is a discrepancy between their values. Some digging revealed this to be the result of them being private/protected, and inheritance somehow got messed up. I have a Product that has a rebate applied, and the following code:

Code: Select all

<?php dump($product->getPrice()->getRebate()); ?>
<?php dump($product->getPrice()); ?>
produces the following dump:

Code: Select all

"0.00"

Standard {#1050 ▼
  -values: array:19 [▼
    "price.id" => "1537"
    "price.siteid" => "1"
    "price.typeid" => "3"
    "price.currencyid" => "HUF"
    "price.domain" => "product"
    "price.label" => "HUF 4990"
    "price.quantity" => "1"
    "price.value" => "4990.00"
    "price.costs" => "0.00"
    "price.rebate" => "0.00"
    "price.taxrate" => "27.00"
    "price.status" => "1"
    "price.mtime" => "2016-11-14 09:50:26"
    "price.editor" => ""
    "price.ctime" => "2016-11-06 00:22:36"
    "price.type" => "default"
    "price.typename" => "Standard"
    "price.taxflag" => true
    "price.tax" => "1060.8661"
  ]
  -listItems: []
  -refItems: []
  -sortedLists: []
  -prefix: "price."
  -modified: true
  -values: array:18 [▼
    "price.id" => "1537"
    "price.siteid" => "1"
    "price.typeid" => "3"
    "price.currencyid" => "HUF"
    "price.domain" => "product"
    "price.label" => "HUF 4990"
    "price.quantity" => "1"
    "price.value" => "4990.00"
    "price.costs" => "0.00"
    "price.rebate" => "2220.00"
    "price.taxrate" => "27.00"
    "price.status" => "1"
    "price.mtime" => "2016-11-14 09:50:26"
    "price.editor" => ""
    "price.ctime" => "2016-11-06 00:22:36"
    "price.type" => "default"
    "price.typename" => "Standard"
    "price.taxflag" => true
  ]
  +"position": 0
}
So the rebate is contained in the Price object, but getRebate returns the wrong value.
We are using aimeos 2016.10 with Laravel 5.1.

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

Re: Pubilc Rebate Price in Basket

Post by aimeos » 14 Nov 2016, 11:05

According to your object, getRebate() should return "2220.00".
The first array contains the initial values from the database which are stored in the base class of the item. The second array additionally contains the changes you've made. Besides id, siteid, ctime, mtime and editor, no values are used from the first array.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Pejka
Posts: 17
Joined: 24 Oct 2016, 11:04

Re: Pubilc Rebate Price in Basket

Post by Pejka » 14 Nov 2016, 11:20

Yet it returns "0.00". Nevermind, I set the getRawValues function on the MShop\Common\Item\Base to public, it returns the correct values. As I see it nothing actually uses that function so it should be okay.

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

Re: Pubilc Rebate Price in Basket

Post by aimeos » 14 Nov 2016, 11:44

You will loose the ability to update your Aimeos installation if you change the core in that way. Therefore, we strongly advice for another way to solve this.

The problem seems to be a bug in PHP regarding inheritance of private variables, which must not occur.
Can you please rename in https://github.com/aimeos/aimeos-core/b ... m/Base.php:
- "private $values" to "private $basevals" and
- "$this->values" to "$this->basevals"
If this solves the problem too, we will add this to the core an release a new version for you immediately.

Thanks a lot!
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Pejka
Posts: 17
Joined: 24 Oct 2016, 11:04

Re: Pubilc Rebate Price in Basket

Post by Pejka » 14 Nov 2016, 12:39

We tried monkeying around with those before, and came to the same conclusion, it should not happen that there are two properties under the same name.
Renaming $values to $basevals creates an error so majestic it breaks somewhere along the lines of setting up basic site data:

Code: Select all

Exception in Standard.php line 518: Locale item for site "default" not found
First few lines of stack:

Code: Select all

 in Standard.php line 518
at Standard->bootstrapBase('default', '', 'HUF', true, object(Standard), array(null), array(null)) in Standard.php line 131
at Standard->bootstrap('default', '', 'HUF', true)
at call_user_func_array(array(object(Standard), 'bootstrap'), array('default', '', 'HUF', true)) in Base.php line 51
at Base->__call('bootstrap', array('default', '', 'HUF', true)) in Locale.php line 64
We've discovered this weird behaviour about last week, but back then it wasn't a problem, I just found it curious, but it seems to have at least some implications.

It seems to be a fringe issue, on the product details page the price object is loaded correctly in the price/partials-default.php with $priceItems = $this->get( 'prices', array() ); this only seems to come up if I use something like $product->getPrice(), where $product is an Mshop\Order\Item\Base\Product\Standard object.

Alas, we keep a document handy where we document any changes to any files that may be overwritten with an update. Sometimes it may become evident that there was a built-in solution that's easier, but sometimes it's necessary...

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

Re: Pubilc Rebate Price in Basket

Post by aimeos » 14 Nov 2016, 13:06

You shouldn't be forced to make any changes to the core to work around PHP bugs. That's our task because others will probably have this problem too ;-)

Can you please change your composer.json to use the

Code: Select all

"aimeos/aimeos-core": "2016.10.x-dev"
and execute

Code: Select all

composer update
You should then get revision "9bd3790", which contains the changes I've mentioned without breaking anything else.
Can you tell me after you revert your getRawValues() change if it works as expected?

Thanks
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Pejka
Posts: 17
Joined: 24 Oct 2016, 11:04

Re: Pubilc Rebate Price in Basket

Post by Pejka » 14 Nov 2016, 14:58

Took a little longer than expected to set up an alternate site for testing, and sadly, I don't see any changes :(

Code: Select all

dump($product->getPrice()->getRebate());
 dump($product->getPrice());
still yields

Code: Select all

"0.00"

Standard {#1031 ▼
  -values: array:19 [▼
    "price.id" => "1537"
    "price.siteid" => "1"
    "price.typeid" => "3"
    "price.currencyid" => "HUF"
    "price.domain" => "product"
    "price.label" => "HUF 4990"
    "price.quantity" => "1"
    "price.value" => "4990.00"
    "price.costs" => "0.00"
    "price.rebate" => "0.00"
    "price.taxrate" => "27.00"
    "price.status" => "1"
    "price.mtime" => "2016-11-14 09:50:26"
    "price.editor" => ""
    "price.ctime" => "2016-11-06 00:22:36"
    "price.type" => "default"
    "price.typename" => "Standard"
    "price.taxflag" => true
    "price.tax" => "1060.8661"
  ]
  -listItems: []
  -refItems: []
  -sortedLists: []
  -prefix: "price."
  -basevals: array:18 [▼
    "price.id" => "1537"
    "price.siteid" => "1"
    "price.typeid" => "3"
    "price.currencyid" => "HUF"
    "price.domain" => "product"
    "price.label" => "HUF 4990"
    "price.quantity" => "1"
    "price.value" => "4990.00"
    "price.costs" => "0.00"
    "price.rebate" => "2220.00"
    "price.taxrate" => "27.00"
    "price.status" => "1"
    "price.mtime" => "2016-11-14 09:50:26"
    "price.editor" => ""
    "price.ctime" => "2016-11-06 00:22:36"
    "price.type" => "default"
    "price.typename" => "Standard"
    "price.taxflag" => true
  ]
  -modified: true
  +"position": 0
}
Although I'm not exactly sure where exactly I should have put "aimeos/aimeos-core": "2016.10.x-dev" in the composer.json file, since there is already a line "aimeos/aimeos-laravel": "~2016.10". Right now it looks like this:

Code: Select all

...stuff
"require": {
    "aimeos/aimeos-core": "2016.10.x-dev",
    "aimeos/aimeos-laravel": "~2016.10",
    "laravel/framework": "~5.1",
more stuff...
How do I know I got the correct version?

EDIT: wait, I got it, composer/installed.json reads:

Code: Select all

"name": "aimeos/aimeos-core",
        "version": "2016.10.x-dev",
        "version_normalized": "2016.10.9999999.9999999-dev",
        "source": {
            "type": "git",
            "url": "https://github.com/aimeos/aimeos-core.git",
            "reference": "9bd37902955b1aa75386aaedb5e276057efa3735"
        },
        "dist": {
            "type": "zip",
            "url": "https://api.github.com/repos/aimeos/aimeos-core/zipball/9bd37902955b1aa75386aaedb5e276057efa3735",
            "reference": "9bd37902955b1aa75386aaedb5e276057efa3735",
            "shasum": ""
        },
So I guess this should be it?

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

Re: Pubilc Rebate Price in Basket

Post by aimeos » 14 Nov 2016, 16:49

Your problem is a different one. This is not related to a PHP bug but when you add a product to the basket, the rebate value is cleared because the rebate field is then used by the coupon providers:
https://github.com/aimeos/ai-controller ... d.php#L356

The solution might be to add a method getOriginalRebate() to retrieve the rebate like it has been added to the product price. If it should be available after in the order history and the e-mails too, the value must be stored in the order product records as well.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply