Created
May 13, 2025 02:38
-
-
Save kurozumi/e6f928a6cb0fafa3836c124561662a62 to your computer and use it in GitHub Desktop.
商品データフィードプラグインの Google 用の商品データフィードに商品カテゴリを追加する方法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Customize\Service\Feed\Google\Attribute; | |
use Eccube\Entity\ProductCategory; | |
use Eccube\Entity\ProductClass; | |
use Plugin\ProductFeedExporter\Service\Feed\Google\AttributeInterface; | |
class ProductType implements AttributeInterface | |
{ | |
public function key(): string | |
{ | |
return 'product_type'; | |
} | |
public function value(ProductClass $productClass): ?string | |
{ | |
if ($productClass->getProduct()->getProductCategories()) { | |
/** @var ProductCategory $productCategory */ | |
$productCategory = $productClass->getProduct()->getProductCategories()->first(); | |
$category = $productCategory->getCategory(); | |
$categories = array_merge([$category->getName()], $category->getDescendants()); | |
return implode(' > ', $categories); | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment