cv65kr/sylius-personalized-products

Personalized products, choices by machine learning (Prediction IO) for Sylius.

This package is auto-updated.

Last update: 2024-03-29 03:44:45 UTC


README

Overview

I used Apache PredictionIO to create plugin, which shows personalize recommended products, based on watched products.

Installation

Sylius

composer require cv65kr/sylius-personalized-products

Add plugin dependencies to your AppKernel.php file:

public function registerBundles()
{
    return array_merge(parent::registerBundles(), [
        ...
        
        new \cv65kr\SyliusPersonalizedProducts\SyliusPersonalizedProductsPlugin(),
    ]);
}

Import required config in your app/config/config.yml file and setup parameters:

imports:
    ...
    
    - { resource: "@SyliusPersonalizedProductsPlugin/Resources/config/services.yml" }
    
parameters:
    sylius_prediction_event_host: http://machine_learning
    sylius_prediction_event_port: 7070
    sylius_prediction_engine_host: https://machine_learning
    sylius_prediction_engine_port: 8000
    sylius_prediction_key: 'a-mevXQWyArRnxmHvlFKrjHLdjuvhnpqOgYEu8XgvfpLW0RTuPl_wUUQo3ZWQa5F'

Import routing in your app/config/routing.yml file:

app_personalized_products:
    resource: "@SyliusPersonalizedProductsPlugin/Resources/config/routing.yml"

Embed in template:

{{ render(path('sylius_personalized_products_controller')) }}

Note 1: Controller render should be used only for logged customers.

Note 2: You can use limit and template parameres in route.

Apache PredictionIO

First of all, add in docker-compose.yml machine learning:

  machine_learning:
      build: ../ml
      ports:
        - "9000:9000"
        - "7070:7070"
        - "8000:8000"
      volumes:
        - /ml/engine:/CustomEngine

And go inside container:

docker exec -it machine_learning bash

Next:

cd /CustomEngine

We need, download template for 0.9 version:

pio template get apache/predictionio-template-recommender --version v0.3.2 MyRecommendation

Create API key and paste them in Sylius config parameter - sylius_prediction_key:

pio app new SyliusPersonalizedProducts

Let’s verify that our new app is there with this command:

pio app list

In Sylius run:

bin/console s:p:p

And now back into machine_learning container

cd /CustomEngine/MyRecommendation

Build, they may few minutes:

pio build --verbose

Edit engine.json:

vim engine.json

Change:

"appName": "INVALID_APP_NAME"

To:

"appName": "SyliusPersonalizedProducts"

Next train:

Create sample data for training and import them by:

pio import --appid 1 --input data-sample.json

Note: Example sample file, You need modify this file: https://gist.githubusercontent.com/vaghawan/0a5fb8ddb85e03631dd500d7c8f0677d/raw/17487437dd8269588d9dd1ac859b129a43842ba5/data-sample.json

Next run:

pio train

And deploy, hooray!

pio deploy

Contribution

Learn more about our contribution workflow on http://docs.sylius.org/en/latest/contributing/.