Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Created May 13, 2025 02:38
Show Gist options
  • Save kurozumi/e6f928a6cb0fafa3836c124561662a62 to your computer and use it in GitHub Desktop.
Save kurozumi/e6f928a6cb0fafa3836c124561662a62 to your computer and use it in GitHub Desktop.
商品データフィードプラグインの Google 用の商品データフィードに商品カテゴリを追加する方法
<?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