Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add products/attributes as available endpoint. Added notes to readme.… #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@

This is a PHP client for the Magento / Adobe Commerce REST API.

This is a fork of https://github.com/ClickAndMortar/magento-php-api-client

Fork Started: 2024-12-08 by Kraig Larson <kraig@kraiglarson.com>

Fork Purposes:
- Add new API endpoint to get products/attributes
- For my current purposes, needed to reduce PHP version from 8.2 to 8.1

## Requirements

* PHP 8.2 or higher
* PHP 8.1 or higher
* Magento / Adobe Commerce 2.3 or higher

## Installation

```bash
composer require clickandmortar/magento-api-client
composer require kraiglarson/magento-api-client
```

## Usage
Expand Down Expand Up @@ -47,6 +55,7 @@ $product = $client->products->get('24-MB01');
## Available resources

- `products`
- `products/attributes`
- `orders`
- `customers`

Expand Down
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clickandmortar/magento-php-api-client",
"description": "Magento 2 PHP REST API client / SDK",
"name": "kraiglarson/magento-php-api-client",
"description": "Magento 2 PHP REST API client / SDK -- forked from clickandmortar/magento-php-api-client",
"type": "library",
"license": "MIT",
"autoload": {
Expand All @@ -12,10 +12,14 @@
{
"name": "Michael BOUVY",
"email": "michael.bouvy@clickandmortar.fr"
},
{
"name": "Kraig Larson",
"email": "kraig@kraiglarson.com"
}
],
"require": {
"php": ">=8.2",
"php": ">=8.1",
"psr/http-client": "^1.0",
"psr/log": "^3.0",
"psr/http-factory": "^1.0",
Expand Down
21 changes: 21 additions & 0 deletions src/Api/ProductAttributes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace ClickAndMortar\MagentoApiClient\Api;

class ProductAttributes extends AbstractPagedResource
{
public function get(string $sku): array
{
/*
* Note from Kraig Larson <kraig@kraiglarson.com> -- see https://magento.stackexchange.com/questions/303779/magento-2-get-value-of-custom-attribute-on-magento-2-rest-api-v1-orders-items/313072#313072
*/
return $this->resourceClient->getResource(sprintf('/rest/V1/products/attributes/%s', $sku));
}

protected function getPageUri(): string
{
return '/rest/V1/products/attributes';
}
}
4 changes: 3 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use ClickAndMortar\MagentoApiClient\Api\Customers;
use ClickAndMortar\MagentoApiClient\Api\Orders;
use ClickAndMortar\MagentoApiClient\Api\Products;
use ClickAndMortar\MagentoApiClient\Api\ProductAttributes;
use ClickAndMortar\MagentoApiClient\Api\StoreViews;

class Client
Expand All @@ -15,7 +16,8 @@ public function __construct(
public Orders $orders,
public Customers $customers,
public StoreViews $storeViews,
public Products $products
public Products $products,
public ProductAttributes $productAttributes
)
{
}
Expand Down
4 changes: 3 additions & 1 deletion src/ClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use ClickAndMortar\MagentoApiClient\Api\Customers;
use ClickAndMortar\MagentoApiClient\Api\Orders;
use ClickAndMortar\MagentoApiClient\Api\Products;
use ClickAndMortar\MagentoApiClient\Api\ProductAttributes;
use ClickAndMortar\MagentoApiClient\Api\StoreViews;
use ClickAndMortar\MagentoApiClient\Client\HttpClient;
use ClickAndMortar\MagentoApiClient\Client\ResourceClient;
Expand Down Expand Up @@ -65,7 +66,8 @@ public function buildAuthenticatedByOauth(
new Orders($resourceClient, $resourceCursorFactory),
new Customers($resourceClient, $resourceCursorFactory),
new StoreViews($resourceClient, $resourceCursorFactory),
new Products($resourceClient, $resourceCursorFactory)
new Products($resourceClient, $resourceCursorFactory),
new ProductAttributes($resourceClient, $resourceCursorFactory)
);
}

Expand Down