coreshop / CoreShop

CoreShop - Pimcore enhanced eCommerce
http://www.coreshop.org
Other
275 stars 157 forks source link

Call to a member function getPrice() on array #1026

Closed turgic closed 5 years ago

turgic commented 5 years ago
Q A
Bug report? yes/no
Feature request? yes/no
BC Break report? yes/no
RFC? yes/no

Hello guys, I tried to get the price for a product with specific rules, I do :

use CoreShop\Component\Product\Calculator\ProductPriceCalculator;
...
$productPrice = $priceCalculator->getPrice($variant, $shopperContext->getContext())

But I get the error :

Call to a member function getPrice() on array

From what I debug the error comes from /vendor/coreshop/core-sho/src/CoreShop/Component/Core/Product/Calculator/StoreProductPriceCalculator.php :

if (0 === $storeValues->getPrice()) {
            throw new NoRetailPriceFoundException(__CLASS__);
}

$storeValues is an array. Have you an idea ?

turgic commented 5 years ago

@dpfaffenbauer have you an idea please ?

dpfaffenbauer commented 5 years ago

That is quite odd... StoreValues only returns an array if $store is null. In your case, you pass in the whole context as param, which gives you a store. If it doesn't find an store, it throws an exception.... I have absolutely no idea why it isn't working for you. Does it work in the frontend?

turgic commented 5 years ago

@dpfaffenbauer I have the same issue on frontend when I try to open a product. Is odd because the problem appear after running command : bin/console pimcore:deployment:classes-rebuild c

turgic commented 5 years ago

@dpfaffenbauer The problem appear only for products who have variants

dpfaffenbauer commented 5 years ago

try to reinstall everything pls, you messed around too much to understand what really goes on here

turgic commented 5 years ago

@dpfaffenbauer I reinstalled, got the same issue

dpfaffenbauer commented 5 years ago

Completely new? you removed everything and started from scratch? Including Pimcore?

turgic commented 5 years ago

Only i reinstalled coreshop, but I will try right now

turgic commented 5 years ago

@dpfaffenbauer I reinstall both : pimcore and coreshop and get the same issue :(

dpfaffenbauer commented 5 years ago

I have no idea... can you give more context. It works for me on multiple installations...

turgic commented 5 years ago

@dpfaffenbauer The problem appear only for variants. So for basic product $storeValues = $subject->getStoreValues($context['store']); the return is object But for variants the return is an array of objects.

dpfaffenbauer commented 5 years ago

More information pls, what Pimcore Version?

turgic commented 5 years ago

@dpfaffenbauer "require": { "php": ">=7.1", "cocur/slugify": "^3.1", "coreshop/core-shop": "dev-master", "divante-ltd/coreshop-vsbridge": "dev-master", "gesdinet/jwt-refresh-token-bundle": "^0.5.3", "gfreeau/get-jwt-bundle": "^2.0", "nelmio/cors-bundle": "^1.5", "ongr/elasticsearch-bundle": "^5.2", "pimcore/pimcore": "~5.8.0", "symfony-bundles/json-request-bundle": "^2.0", "wikimedia/composer-merge-plugin": "^1.4" },

turgic commented 5 years ago

I confirm that on normal product works fine, but when I tried to get the price for product variant I have this issue

turgic commented 5 years ago

In the function /var/classes/DataObject/CoreShopProduct.php getStoreValues() :

public function getStoreValues (\CoreShop\Component\Store\Model\StoreInterface $store = null) {
    $this->storeValues = $this->getClass()->getFieldDefinition("storeValues")->preGetData($this);
        if (is_null($store)) {
        return $this->storeValues;
    }
    ....
}

$this->storeValues is null, have you an idea ? Any ideas @dpfaffenbauer please ?

turgic commented 5 years ago

@dpfaffenbauer are you here ?

dpfaffenbauer commented 5 years ago

I am, but I am also busy with other stuff.

I will look at your issue, but not straight away, this is open-source work, I do it for free, so please don't except immediate support for problems you have with free software!

turgic commented 5 years ago

@dpfaffenbauer I found a possible error : in /var/classes/DataObject/CoreShopProduct function getStoreValues(), here :

try {
            return $this->getValueFromParent("storeValues");
        } catch (InheritanceParentNotFoundException $e) {
            // no data from parent available, continue ... 
        }
dpfaffenbauer commented 5 years ago

1028 fixes your issue. Will still take some time to be merged though.

turgic commented 5 years ago

Have you a date when is supposed to be merged ? And in which coreshop version ? Thx @dpfaffenbauer

dpfaffenbauer commented 5 years ago

later today or tomorrow morning. it is in master branch, so 2.1-dev

turgic commented 5 years ago

Thank you @dpfaffenbauer

dpfaffenbauer commented 5 years ago

@turgic it is merged!

turgic commented 5 years ago

Thank you @dpfaffenbauer