承接 bestit/commercetools-odm 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱: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"

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固