定制 overplex/google-feed-generator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

overplex/google-feed-generator

Composer 安装命令:

composer require overplex/google-feed-generator

包简介

Google Merchant Feed file generator

README 文档

README

About

Google Merchant Feed file generator. Uses standard XMLWriter for generating Google Merchant Feed XML file. Not required any other library you just need PHP 5.5.0 or >= version.

Installation

Run composer require

composer require overplex/google-feed-generator

Or add this to your composer.json file:

"require": {
  "overplex/google-feed-generator": "dev-master",
}

Usage example

<?php

use overplex\GoogleFeedGenerator\product\Availability;
use overplex\GoogleFeedGenerator\product\Condition;
use overplex\GoogleFeedGenerator\product\Product;
use overplex\GoogleFeedGenerator\GoogleFeedFile;
use overplex\GoogleFeedGenerator\Settings;

// Create second (unbuffered) connection to database (only for Yii 2)
$unbufferedDb = new \yii\db\Connection([
    'dsn' => \Yii::$app->db->dsn,
    'charset' => \Yii::$app->db->charset,
    'username' => \Yii::$app->db->username,
    'password' => \Yii::$app->db->password,
    'tablePrefix' => \Yii::$app->db->tablePrefix,
]);
$unbufferedDb->open();
$unbufferedDb->pdo->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);

// Writing header to google_feed.xml
$feed = new GoogleFeedFile('My best shop', 'http://www.myshop.com/', 'Description of my shop',
    (new Settings())->setOutputFile('google_feed.xml')
);

// Writing products
/** @var ProductModel $product */
foreach ($this->getProductsQuery()->each(50, $unbufferedDb) as $product) {
    $feed->addProduct((new Product())
        ->setId($product->id)
        ->setMpn($product->articul)
        ->setLink($product->getViewAbsoluteUrl())
        ->setImage($product->getMainPhotoAbsoluteUrl())
        ->setTitle($product->name)
        ->setPrice($product->getOldPrice() . ' RUB')
        ->setSalePrice($product->getPrice() . ' RUB')
        ->setCondition(Condition::NEW_PRODUCT)
        ->setDescription($product->description)
        ->setAvailability($product->in_stock
            ? Availability::IN_STOCK
            : Availability::OUT_OF_STOCK)
        ->setLength($product->depth, 'cm')
        ->setWidth($product->width, 'cm')
        ->setHeight($product->height, 'cm')
        ->setWeight($product->weight, 'kg')
        ->setGoogleCategory($categoryId)
        ->setBrand($vendor));
    gc_collect_cycles();
}

$feed->finish();
$unbufferedDb->close();

Copyright / License

See LICENSE

统计信息

  • 总下载量: 3.03k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固