bestit/commercetools-odm 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

bestit/commercetools-odm

Composer 安装命令:

composer require bestit/commercetools-odm

包简介

Makes the commercetools database accessible with the doctrine commons api.

README 文档

README

Wraps the commercetools/php-sdk with the doctrine common api.

Installation

Step 1: Download

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require bestit/commercetools-odm

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable

The central script of the odm is the BestIt\CommercetoolsODM\DocumentManager based on the Doctrine\Common\Persistence\ObjectManager. Just fill it with its dependencies and you are good to go.

You could use our bestit/commercetools-odm-bundle to kickstart your project.

Usage

A small example usage:

<?php

// Load the product repository.
/** @var \BestIt\CommercetoolsODM\DocumentManagerInterface $documentManager */
/** @var \BestIt\CommercetoolsODM\Repository\ProductRepository $repository */
$repository = $documentManager->getRepository(\Commercetools\Core\Model\Product\Product::class);

// Fetch it from the database or create a new instance.
/** @var \Commercetools\Core\Model\Product\Product $product */
$product = $repository->findByKey($key) ??
    $documentManager->getClassMetadata(\Commercetools\Core\Model\Product\Product::class)->getNewInstance();

// Do your work.
if (!$product->getId()) {
    $product
        ->setProductType(\Commercetools\Core\Model\ProductType\ProductTypeReference::ofId('type'))
        // ....
}

// You get automatic but simple 409 conflict resolution if you use  this callback. If not, 409s lead to an exception. 
$documentManager->modify($product, function(\Commercetools\Core\Model\Product\Product $product) {
    $product->setKey('new-key');
});

// Persist the changes
$documentManager->persist($product);

// Detach it from the document manager (UnitOfWork) after flush.
$documentManager->detachDeferred($product);

// Flush the changes in the document manager to the repository.
$documentManager->flush();

Contribute

Some advices to contribute to this library ...

Metadata

This is the main problem of this library: How to map the structure of the commercetools sdk to a unified api. We resolved it for the moment with a map:

<?php
// ./src/Resources/config/metadata.php

use BestIt\CommercetoolsODM\Mapping\Annotations\RequestMap;

return [
    // Your model
    \Commercetools\Core\Model\Cart\Cart::class => [
        // The draft class for creating a new model
        'draft' => \Commercetools\Core\Model\Cart\CartDraft::class,
        // Which repo to use
        'repository' => \BestIt\CommercetoolsODM\Repository\CartRepository::class,
        // And the map for every needed request type.
        'requestClassMap' => (new RequestMap())
            ->setCreate(\Commercetools\Core\Request\Carts\CartCreateRequest::class)
            ->setDeleteById(\Commercetools\Core\Request\Carts\CartDeleteRequest::class)
            ->setFindById(\Commercetools\Core\Request\Carts\CartByIdGetRequest::class)
            ->setFindByCustomerId(\Commercetools\Core\Request\Carts\CartByCustomerIdGetRequest::class)
            ->setQuery(\Commercetools\Core\Request\Carts\CartQueryRequest::class)
            ->setUpdateById(\Commercetools\Core\Request\Carts\CartUpdateRequest::class)
    ],

    // ... map more models
];

Action Builder

Even if we work object oriented, we still support the partial updates of commercetools. Please consult the interface BestIt\CommercetoolsODM\ActionBuilder\ActionBuilderInterface to add your own action builder. The action builders create the request actions to commercetools matching the changed property values.

Reset your cache, after changing the action builder setup.

Further steps

  • Work with less assumptions, for example, every standard model has an id and version
  • Remove hard coupling to the publish marker on the product to publish the staged version
  • Add every action builder. Not every thing is there at the moment.
  • More unittesting
  • More documentation
  • Harmonize naming: Move away from "documents" to "objects"

bestit/commercetools-odm 适用场景与选型建议

bestit/commercetools-odm 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24.85k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2017 年 04 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 bestit/commercetools-odm 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 bestit/commercetools-odm 我们能提供哪些服务?
定制开发 / 二次开发

基于 bestit/commercetools-odm 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-04-16