Skip to content

Commit

Permalink
Merge pull request #15 from suraj-webkul/update-docs
Browse files Browse the repository at this point in the history
Updating docs.
  • Loading branch information
devansh-webkul authored Jul 1, 2024
2 parents de73751 + ccdcf4f commit 29d94a8
Show file tree
Hide file tree
Showing 34 changed files with 2,918 additions and 1,967 deletions.
1 change: 0 additions & 1 deletion docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module.exports = {
base: '/',
port: '8080',
cache: false,
title: 'Documentation',
description: 'Krayin CRM Developer Portal',
head: [
['link', { rel: "icon", type: "image/png", href: "/favicon.ico"}],
Expand Down
8 changes: 8 additions & 0 deletions docs/.vuepress/theme/components/Page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ export default {
padding-bottom 2rem
display block
.table-of-contents ul
list-style-type none
color #0041FF
.table-of-contents ul li:before
content '\0023'
position absolute
margin-left -16px
</style>
1 change: 0 additions & 1 deletion docs/.vuepress/version-configs/1.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ module.exports = [
collapsable: true,
children: setVersionPrefix([
['architecture/packages', 'Packages'],
['architecture/frontend', 'Frontend'],
['architecture/repository-pattern', 'Repository Pattern'],
['architecture/modular-design', 'Modular Design']
]),
Expand Down
18 changes: 1 addition & 17 deletions docs/1.x/advanced/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@ Welcome to the "Digging Deeper" section of the Krayin documentation. Here, we wi

We expect you to have knowledge of creating packages in Laravel. If you are new to package development, we recommend referring to the [Package Development](../packages/create-package.html) section for a primer on creating and managing packages in Laravel.

### Creating Payment Methods

Krayin provides a flexible and configurable system for integrating different payment methods into your e-commerce store. We will guide you through the process of setting up and configuring payment methods, allowing you to offer a variety of options to your customers while ensuring a seamless and secure checkout experience.

### Product Types

Krayin supports different types of products, allowing you to showcase and sell a wide range of items. We will delve into the details of configuring and managing product types, giving you the ability to define specific attributes and behaviors for each product category.

### Shipping Methods

Efficient and reliable shipping is crucial for any e-commerce business. Krayin offers robust features for managing shipping methods, enabling you to define various shipping options, rates, and rules based on factors such as location, weight, or order value. We will explain how to configure and customize shipping methods to streamline your order fulfillment process.

### Events and Event Handlers

Events and event handlers provide a powerful way to extend the functionality of Krayin by allowing you to react to specific actions or triggers within the application. We will show you how to utilize events and event handlers effectively, enabling you to integrate custom functionalities and automate processes.
Expand All @@ -24,10 +12,6 @@ Events and event handlers provide a powerful way to extend the functionality of

Krayin includes a comprehensive set of helper functions that simplify common development tasks and enhance productivity. We will explore the various helper functions available, explaining their purpose and usage to assist you in writing clean and efficient code.

### Indexing through Elastic

To optimize search performance, Krayin integrates with Elasticsearch, a highly scalable search engine. We will guide you through the process of indexing your data using Elastic, improving the search functionality of your e-commerce store and providing a seamless search experience for your customers.

### Overriding Core Models

Sometimes, you may need to modify or extend the default behavior of Krayin's core models to accommodate your specific business requirements. We will demonstrate how to override core models effectively, enabling you to customize the behavior of Krayin without modifying the underlying codebase.
Sometimes, you may need to modify or extend the default behavior of Krayin's core models to accommodate your specific business requirements. We will demonstrate how to override core models effectively, enabling you to customize the behavior of Krayin without modifying the underlying codebase.
384 changes: 232 additions & 152 deletions docs/1.x/advanced/events.md

Large diffs are not rendered by default.

117 changes: 81 additions & 36 deletions docs/1.x/advanced/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,101 +4,146 @@

## Introduction

Krayin provides several helper methods in its packages, which are designed to assist developers in building their projects more efficiently.
Krayin provides a range of helper methods in its packages to streamline and simplify the development process. These helpers are designed to offer utility functions that facilitate common tasks, reducing the amount of boilerplate code developers need to write and enhancing overall productivity.

## Core Helpers

The core helper methods mentioned below are part of the `Core` class in the `Webkul\Core` namespace. Let's explore some common methods:
The core helper methods are part of the Core class in the `Webkul\Core` namespace. These methods provide essential functionality that can be utilized across different parts of the application, making development more efficient and consistent. Let's explore some common methods:

- **Get currency symbol from currency code.**
### Get the lists of timezone

To retrieve a list of timezones in the CRM, you can use the `core()->timezones()` method, which returns the list of timezones.

```php
core()->currencySymbol($amount)
core()->timezones();
```

- **Format and convert price with currency symbol.**
### Get the list of available locals

- **Format price with base currency symbol. This method also give ability to encode the base currency symbol and its optional.**
To retrieve a list of available local in the CRM, you can use the `core()->locales()` method, which return the list of available locales

```php
core()->formatBasePrice($price, $isEncoded = false)
core()->locales();
```
- **Format date using current channel.**

### Get the list of countries

To retrieve a list of countries in the CRM, you can use the `core()->countries()` method, which returns the list of all countries within the CRM.

```php
core()->formatDate($date = null, $format = 'd-m-Y H:i:s')
core()->countries();
```

- **Retrieve information from configuration.**
### Get the country name

To retrieve the country name by its country code, you can use the `core()->country_name($code)` method, which returns the name of the country associated with the specified country code.

```php
core()->getConfigData($field, $channel = null, $locale = null)
core()->country_name($code);
```

- **Retrieve all countries.**
### Get the available states associated with country code

To retrieve a list of states associated with states in the CRM, you can use the `core()->states($countryCode)` method, which returns the all states associated with the country code.

```php
core()->states($countryCode);
```

### Get the specified state name associated with state code

To retrieve the state name by its state code, you can use the `core()->state_name($code)` method, which returns the name of the state name associated with the specified state code.

```php
core()->state_name($code);
```

### Get the Grouped the states by the countries

To retrieve the grouped the states by the countries, you can use the `core()->findStateByCountryCode($countryCode, $stateCode)` which takes two argument `$countryCode` and `$stateCode`.

```php
core()->countries()
core()->findStateByCountryCode($countryCode, $stateCode);
```

- **Get country name by code.**
### To Sort the items

Method to sort through the acl items and put them in order.

```php
core()->country_name($code)
```
core()->sortItems($items);
```

- **Retrieve all country states.**
### Set a value in an array using dot notation

This method allows setting values in a nested array using dot notation for keys. If the key does not exist, it creates nested arrays as necessary to set the value. If the key already exists, it merges the existing value with the new value.

```php
core()->states($countryCode)
core()->array_set($array, $key, $value);
```

- **Retrieve all grouped states by country code.**
### To converted associated array

To converted associated array into the CRM, you can use the `core()->convertToAssociativeArray($items)` .

```php
core()->groupedStatesByCountries()
core()->convertedToAssociativeArray($items);
```

- **Get states by country code.**
### To merge the array

To merge the array into the CRM, you can use the method of `core()->arrayMerge(array &array1, array &array2)`.

```php
core()->findStateByCountryCode($countryCode = null, $stateCode = null)
core()->arrayMerge($items);
```

- **Method to sort through the acl items and put them in order.**
### Create singleton object through single facade

You can use the core method for singleton binding through the core helper methods.

```php
core()->sortItems($items)
core()->getSingletonInstance($className)
```

- **Get config field.**
### Format Date

You can use `core()->formatDate($date, $format = 'd M Y h:iA')` method to format the provided date, you can modify the format date structure by passing second argument.

```php
core()->getConfigField($fieldName)
```
core()->formatDate($date, $format);
```

### Return currency symbol from currency code

- **Convert to associative array.**
To get the symbol of current currency int the crm you can use the method of core helper

```php
core()->convertToAssociativeArray($items)
core()->currencySymbol($code);
```

- **Array set.**
### Format base price

To format the price of provided price you can use the method `core()->formatBasePrice()`

```php
core()->array_set(&$array, $key, $value)
core()->formatBasePrice($price);
```

- **Create singleton object through single facade.**
### Get the config field

To get the config field you can use the `core()->getConfigField($fieldName)`

```php
core()->getSingletonInstance($className)
core()->getConfigField($fieldName);
```

- **Array merge.**
### Get the config data

To retrieve the config data you can use the method `core()->getConfigData($field)`

```php
core()->arrayMerge(array &$array1, array &$array2)
```
core()->getConfigData($field);
```

These core helper methods provide various functionalities to simplify common tasks and streamline development in Krayin.
89 changes: 50 additions & 39 deletions docs/1.x/advanced/override-core-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,72 @@

Krayin utilizes Concord, a Laravel extension, for building modules on top of Laravel's built-in service providers. Concord introduces the concept of model proxies, which allow you to override and extend core models in a modular way.

Concord requires the existence of an interface, such as **Category**, which serves as a contract that can be bound to a concrete class using Concord's **registerModel()** method.
Concord requires the existence of an interface, such as `Product`, which serves as a contract that can be bound to a concrete class using Concord's `registerModel()` method.

By default, the **`Models\Category`** class is bound to the **`Contracts\Category`** interface within the module. If you want to extend or override this class, you can use Concord's **registerModel()** method.
By default, the `Models\Product` class is bound to the `Contracts\Product` interface within the module. If you want to extend or override this class, you can use Concord's `registerModel()` method.

The **registerModel()** method handles the binding of the interface and implementation in Laravel's service container, enabling you to easily type-hint the interface for automatic injection.
The `registerModel()` method handles the binding of the interface and implementation in Laravel's service container, enabling you to easily type-hint the interface for automatic injection.

For more details, you can visit the [Concord GitHub repository](https://github.com/artkonekt/concord) or refer to the [Concord documentation](https://artkonekt.github.io/concord/#/).

## Overriding a Model Class

- In Concord modules, an interface is typically defined for each Eloquent model. If you wish to override a model, you can instruct Concord to use another class for that interface. Here's an example:
To override a core model in Krayin using Concord, follow these steps:

```php
<?php
### Define an Interface (Contract)

namespace Webkul\Category\Providers;
In Krayin's modular structure, each Eloquent model typically corresponds to an interface. This interface acts as a contract that specifies the methods the model must implement.

use Illuminate\Support\ServiceProvider;
### Register the Model Override

class CategoryServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//...

$this->app->concord->registerModel(
\Webkul\Category\Contracts\Category::class, \App\Http\Category::class
);
}
}
```
Use Concord's registerModel() method in your module's service provider (ServiceProvider) to bind your custom model implementation to the interface. Here’s how you can do it:

- In the code above, the **registerModel()** method accepts two parameters:
```php
<?php

- The first parameter specifies the path to the interface (contract) you want to override.
- The second parameter specifies the path to the model class that will override the default implementation.
namespace Webkul\Category\Providers;

- The model class you're overriding must extend your specified model path, as shown in the example below:
use Illuminate\Support\ServiceProvider;

```php
<?php
class CategoryServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
// ...

$this->app->concord->registerModel(
\Webkul\Product\Contracts\Product::class, \App\Http\Product::class
);
}
}
```

namespace App\Http;
- Replace `\Webkul\Product\Contracts\Product::class` with the interface you wish to override.
- Replace `\App\Http\Product::class` with the path to your custom model class that extends the core model you are overriding.

use Webkul\Category\Models\Category as CategoryBaseModel;
### Implement the Custom Model Class

class Category extends CategoryBaseModel
{
//
}
```
Your custom model class (Product in this example) should extend the base core model (`ProductBaseModel`), ensuring it adheres to the contract specified by the interface. Here’s an example:

```php
<?php

namespace App\Http;

use Webkul\Product\Models\Product as ProductBaseModel;

class Product extends ProductBaseModel
{
//
}
```

Once registered, you can use dependency injection or other Laravel mechanisms to reference the interface(`\Webkul\Product\Contracts\Product::class`) throughout your application. Laravel's service container will automatically resolve your custom model implementation (`\App\Http\Product::class`) where the interface is referenced.

By following this approach, you can effectively extend and override core models within Krayin using Concord, maintaining modularity and flexibility in your application's architecture.

By following this approach, you can override core models in Krayin using Concord's module system.
Loading

0 comments on commit 29d94a8

Please sign in to comment.