Commit 4f3ff447 by liumengfei

优化goog feed生成文件

parent b54ae75b
......@@ -3,6 +3,7 @@
namespace Joshine\GoogleFeed\Console\Command;
use Magento\Framework\App\State;
use Magento\Setup\Exception;
use Magento\Store\Model\Store;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
......@@ -233,6 +234,11 @@ class GoogleFeed extends Command
$productRows['header'] = $this->generateRow($this->columns);
foreach ($products as $key => $product) {
//去除没有主产品的子产品
$configProductIds = $this->configurable->getParentIdsByChild($product->getId());
if (empty($configProductIds)){
continue;
}
$_product = $this->productRepository->getById($product->getId());
$data = $this->generateProductData($_product,$categoryGoogleProductCategory);
if (count($data) > 0) {
......@@ -284,7 +290,14 @@ class GoogleFeed extends Command
$data['id'] = $product->getSku();
$data['title'] = $this->getStoreName() .' '. str_replace('"', '\'', $product->getName());
$data['description'] = strip_tags(str_replace('"', '\'', $product->getDescription()));
//获取主产品描述信息
if (empty($data['description'])){
var_dump($product->getSku());
$desc = $this->getConfigProductDescription($product);
if (!empty($desc)){
$data['description'] = strip_tags(str_replace('"', '\'', $desc));
}
}
foreach( $product->getCategoryIds() as $k=>$v){
if (isset($categoryGoogleProductCategory[$v])){
......@@ -375,6 +388,29 @@ class GoogleFeed extends Command
return $name;
}
public function getConfigProductDescription($product){
$configProductIds = $this->configurable->getParentIdsByChild($product->getId());
if (!$configProductIds){
return "";
}
if(is_array($configProductIds) && !empty($configProductIds)){
$configProductId = $configProductIds[0];
}
if(is_int($configProductIds)){
$configProductId = $configProductIds;
}
$configurablProduct =$this->productRepository->getById($configProductId, false, $product->getStoreId());
try {
$desc = $configurablProduct->getCustomAttribute("description");
}catch (Exception $e){
$desc = false;
}
if ($desc){
return $desc->getValue();
}
return "";
}
public function getConfigProductUrl($product){
$configProductIds = $this->configurable->getParentIdsByChild($product->getId());
if (!$configProductIds){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment