Skip to content

Commit

Permalink
feat(WishListProduct): add product feature on open_api (#33)
Browse files Browse the repository at this point in the history
Co-authored-by: Maxime Bruchet <mbruchet@openstudio.fr>
  • Loading branch information
mabruchet and Maxime Bruchet authored Dec 19, 2024
1 parent ec3e2b8 commit c0a6b02
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>2.3.0</version>
<version>2.4.0</version>
<authors>
<author>
<name>Michaël Espeche</name>
Expand Down
49 changes: 49 additions & 0 deletions Model/Api/WishListProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use OpenApi\Annotations as OA;
use OpenApi\Model\Api\BaseApiModel;
use Thelia\Model\Base\FeatureProduct;
use Thelia\Model\ProductImage;
use Thelia\Model\ProductSaleElements;

Expand Down Expand Up @@ -37,6 +38,17 @@ class WishListProduct extends BaseApiModel
*/
protected $images;

/**
* @var array
* @OA\Property(
* type="array",
* @OA\Items(
* ref="#/components/schemas/Feature"
* )
* )
*/
protected $features = [];

/**
* @var string
* @OA\Property(
Expand Down Expand Up @@ -93,6 +105,38 @@ function (ProductImage $productImages) {

$wishListProduct->setUrl($pse->getProduct()->getUrl());

$currentProduct = $pse->getProduct();
$modelFactory = $this->modelFactory;

$this->features = array_filter(
array_map(
function (FeatureProduct $featureProduct) use ($modelFactory) {
$propelFeature = $featureProduct->getFeature();
if (null === $propelFeature) {
return false;
}

if (null !== $featureProduct->getFeatureAv()) {
// Temporary set only product feature av to build good feature av list
$propelFeature->addFeatureAv($featureProduct->getFeatureAv());
}
$propelFeature->resetPartialFeatureAvs(false);

$feature = $modelFactory->buildModel('Feature', $propelFeature);

$propelFeature->clearFeatureAvs();

return $feature;
},
iterator_to_array(
$currentProduct->getFeatureProducts()
)
),
function ($value) {
return $value;
}
);

return $wishListProduct;
}

Expand Down Expand Up @@ -202,4 +246,9 @@ public function setUrl(string $url): WishListProduct

return $this;
}

public function getFeatures(): array
{
return $this->features;
}
}

0 comments on commit c0a6b02

Please sign in to comment.