Skip to content

Commit

Permalink
huuuuge wip
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLambauer committed Aug 1, 2023
1 parent 4715e95 commit d76a02f
Show file tree
Hide file tree
Showing 109 changed files with 12,203 additions and 1,482 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Mage-OS Documentation

[TOC]

You can find the online version of the Mage-OS documentation at [https://devdocs.mage-os.org/](https://devdocs.mage-os.org)

## Markup and Features
Expand Down
Empty file removed acl-xml.md
Empty file.
100 changes: 100 additions & 0 deletions acl_xml.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# `acl.xml` Reference Documentation

[TOC]

This reference documentation provides information on the structure and usage of the `acl.xml` file in Magento 2.
`acl.xml` is an essential configuration file used to define Access Control List (ACL) permissions for various
resources in your Magento 2 module or extension.

## Introduction

Access Control List (ACL) is a security mechanism used to control access to resources based on user roles and
permissions. The `acl.xml` file is used in Magento 2 to define these roles, resources, and associated permissions for
your module or extension.

## Structure of `acl.xml`

The `acl.xml` file follows a specific structure and should be placed in the `etc` directory of your module or extension.
Here is an example of the basic structure of `acl.xml`:

```xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
<!-- Define resources and roles here -->
</acl>
</config>
```

The `xmlns:xsi` and `xsi:noNamespaceSchemaLocation` attributes define the XML schema for validation. The `<acl>` tag is
the root element, under which you define resources and roles.

## Defining Resources and Roles

In the `<acl>` tag, you define `<resources>` and `<role>` elements to specify the resources and roles respectively. A
resource represents a specific functionality or area in your module or extension, while a role represents a user role or
group.

Here is an example of defining a resource and a role in `acl.xml`:

```xml
<config>
<acl>
<resources>
<resource id="Namespace_Module::resource_id" title="Resource Title" sortOrder="10">
<!-- Define child resources here -->
</resource>
</resources>

<roles>
<role id="Namespace_Module::role_id" title="Role Title" sortOrder="10">
<!-- Define role's allowed resources here -->
</role>
</roles>
</acl>
</config>
```

In the above example, the `<resource>` element defines a resource with an `id`, `title`, and `sortOrder`. The `id`
should follow the format `<Namespace_Module>::<resource_id>`. Similarly, the `<role>` element defines a role with
an `id`, `title`, and `sortOrder`.

## Applying ACL Permissions

Once you have defined resources and roles, you need to specify the permissions or access rules for each role on the
respective resources. For this, you use the `<resource>` and `<permission>` elements.

Here is an example of applying ACL permissions in `acl.xml`:

```xml
<config>
<acl>
<resources>
<resource id="Namespace_Module::resource_id" title="Resource Title" sortOrder="10">
<resource id="Namespace_Module::child_resource_id" title="Child Resource Title" sortOrder="10">
<permission id="Namespace_Module::permission_id" title="Permission Title" sortOrder="10"/>
</resource>
</resource>
</resources>

<roles>
<role id="Namespace_Module::role_id" title="Role Title" sortOrder="10">
<resource id="Namespace_Module::resource_id" title="Resource Title">
<resource id="Namespace_Module::child_resource_id" title="Child Resource Title">
<permission id="Namespace_Module::permission_id" title="Permission Title"/>
</resource>
</resource>
</role>
</roles>
</acl>
</config>
```

In the above example, the `<permission>` element is nested under the appropriate `<resource>` and `<role>`. The `id`
attribute follows the format `<Namespace_Module>::<permission_id>`. The `title` attribute provides a human-readable
title for the permission.

## Conclusion

The `acl.xml` file is a crucial configuration file in Magento 2 for defining Access Control List (ACL) permissions. By
understanding its structure and usage, you can control access to resources based on user roles and permissions
effectively.
148 changes: 148 additions & 0 deletions api-reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# API Reference Documentation

[TOC]

## Introduction

Welcome to the API Reference Documentation for the Magento 2 API. This comprehensive guide will provide you with all the
necessary information to interact with the Magento 2 API programmatically using PHP.

## Prerequisites

Before you start using the Magento 2 API, make sure you have the following prerequisites:

- Basic knowledge of PHP programming language
- Familiarity with Magento 2 architecture and concepts
- Access to a Magento 2 installation with API access enabled

## API Basics

Magento 2 provides a powerful API that allows you to interact with various aspects of the system, including customers,
products, orders, and more. The API is implemented using the Representational State Transfer (REST) architectural style
and is designed to be platform-agnostic.

To authenticate and interact with the API, you need to obtain an access token, which acts as a credential to
authenticate your requests. You can obtain an access token by authenticating with the Magento 2 OAuth server using your
credentials. Once you have the access token, you can use it to make authorized requests to the API.

## API Endpoints

The Magento 2 API is organized into several endpoints, each representing a different aspect of the system. The endpoints
provide a set of resources and operations that you can use to manipulate and retrieve data.

Here are some of the main API endpoints available in Magento 2:

### Customers

The Customers API endpoint allows you to manage customer-related information, such as creating new customers, retrieving
customer details, updating customer information, and more.

```php
// Example: Retrieve customer details
GET /rest/V1/customers/{customerId}
```

### Products

The Products API endpoint provides methods to manage product-related data, such as creating new products, retrieving
product information, updating product attributes, and more.

```php
// Example: Create a new product
POST /rest/V1/products
```

### Orders

The Orders API endpoint allows you to manage orders in Magento 2, including creating new orders, retrieving order
details, updating order status, and more.

```php
// Example: Retrieve order details
GET /rest/V1/orders/{orderId}
```

### Carts

The Carts API endpoint provides methods to manage shopping carts, including creating new carts, adding products to a
cart, retrieving cart details, and more.

```php
// Example: Create a new cart
POST /rest/V1/carts/mine
```

## Making API Requests

To make API requests, you can use any HTTP client library that supports sending HTTP requests. In PHP, you can use
libraries such as Guzzle, cURL, or the built-in `file_get_contents()` function.

Here's an example of making a GET request to retrieve customer details using the Guzzle HTTP client library:

```php
<?php

use GuzzleHttp\Client;

// Create a new Guzzle HTTP client instance
$client = new Client();

// Make a GET request to retrieve customer details
$response = $client->request('GET', 'https://example.com/rest/V1/customers/1', [
'headers' => [
'Authorization' => 'Bearer {access_token}',
'Content-Type' => 'application/json',
],
]);

// Get the response body
$body = $response->getBody();

// Process the response data
$customer = json_decode($body, true);

// Print the customer details
echo "Customer Name: " . $customer['firstname'] . " " . $customer['lastname'];
```

## Error Handling

When interacting with the Magento 2 API, it's important to handle errors properly. The API returns meaningful error
messages and HTTP status codes to indicate the success or failure of a request.

Here's an example of handling errors when retrieving customer details:

```php
// Make a GET request to retrieve customer details
try {
$response = $client->request('GET', 'https://example.com/rest/V1/customers/1', [
'headers' => [
'Authorization' => 'Bearer {access_token}',
'Content-Type' => 'application/json',
],
]);

// Get the response body
$body = $response->getBody();

// Process the response data
$customer = json_decode($body, true);

// Print the customer details
echo "Customer Name: " . $customer['firstname'] . " " . $customer['lastname'];
} catch (\GuzzleHttp\Exception\RequestException $e) {
// Handle request exceptions (e.g., connection errors, server errors, etc.)
echo "Request Exception: " . $e->getMessage();
} catch (\Exception $e) {
// Handle other exceptions
echo "Exception: " . $e->getMessage();
}
```

## Conclusion

Congratulations! You now have a solid understanding of the Magento 2 API and how to interact with it using PHP. Refer to
the API documentation for further details on available endpoints, request/response formats, and additional
functionality.

Happy coding!
Loading

0 comments on commit d76a02f

Please sign in to comment.