Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Price Calculator Interface in ProductExtractor #892

Merged
merged 1 commit into from
Mar 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/CoreShop/Component/Core/Tracking/Extractor/ProductExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
use CoreShop\Component\Core\Context\ShopperContextInterface;
use CoreShop\Component\Core\Model\CategoryInterface;
use CoreShop\Component\Core\Model\ProductInterface;
use CoreShop\Component\Core\Product\TaxedProductPriceCalculator;
use CoreShop\Component\Core\Product\TaxedProductPriceCalculatorInterface;
use CoreShop\Component\Order\Model\PurchasableInterface;
use CoreShop\Component\Tracking\Extractor\TrackingExtractorInterface;

class ProductExtractor implements TrackingExtractorInterface
{
/**
* @var TaxedProductPriceCalculator
* @var TaxedProductPriceCalculatorInterface
*/
private $taxedPurchasablePriceCalculator;

Expand All @@ -32,11 +32,11 @@ class ProductExtractor implements TrackingExtractorInterface
private $shopperContext;

/**
* @param TaxedProductPriceCalculator $taxedPurchasablePriceCalculator
* @param ShopperContextInterface $shopperContext
* @param TaxedProductPriceCalculatorInterface $taxedPurchasablePriceCalculator
* @param ShopperContextInterface $shopperContext
*/
public function __construct(
TaxedProductPriceCalculator $taxedPurchasablePriceCalculator,
TaxedProductPriceCalculatorInterface $taxedPurchasablePriceCalculator,
ShopperContextInterface $shopperContext
) {
$this->taxedPurchasablePriceCalculator = $taxedPurchasablePriceCalculator;
Expand Down Expand Up @@ -66,15 +66,15 @@ public function updateMetadata($object, $data = []): array
* @var $object PurchasableInterface
*/
return array_merge($data, [
'id' => $object->getId(),
'name' => $object->getName(),
'category' => (is_array($categories) && count($categories) > 0) ? $categories[0]->getName() : '',
'sku' => $object instanceof ProductInterface ? $object->getSku() : '',
'price' => $this->taxedPurchasablePriceCalculator->getPrice($object, $this->shopperContext->getContext()) / 100,
'currency' => $this->shopperContext->getCurrency()->getIsoCode(),
'id' => $object->getId(),
'name' => $object->getName(),
'category' => (is_array($categories) && count($categories) > 0) ? $categories[0]->getName() : '',
'sku' => $object instanceof ProductInterface ? $object->getSku() : '',
'price' => $this->taxedPurchasablePriceCalculator->getPrice($object, $this->shopperContext->getContext()) / 100,
'currency' => $this->shopperContext->getCurrency()->getIsoCode(),
'categories' => array_map(function (CategoryInterface $category) {
return [
'id' => $category->getId(),
'id' => $category->getId(),
'name' => $category->getName(),
];
}, is_array($categories) ? $categories : []),
Expand Down