Slovo-Plugin-Prodan

 view release on metacpan or  search on metacpan

lib/Slovo/Plugin/Prodan.pm  view on Meta::CPAN

      description => 'An array of OrderProduct items in an order.',
      items       => {
        '$ref' => '#/definitions/OrderProduct',
        type   => 'array',

      }
    },
    OrderProduct => {
      description => 'An item in an order (cart): sku, title, quantity, price',
      properties  => {
        sku      => {maxLength => 40,  type => 'string'},
        title    => {maxLength => 155, type => 'string'},
        quantity => {type      => 'integer'},
        weight   => {type      => 'number'},
        price    => {type      => 'number'},
      }
    },
    Consents => {
      properties => {
        ihost               => {type => 'string'},
        gdpr_url            => {type => 'string'},
        delivery_prices_url => {type => 'string'}
      },
      required => [qw(gdpr_url ihost delivery_prices_url)],
    },
  );
}

# Create tables in the database on the very first run if they do not exist.
sub _migrate ($self, $app, $conf) {
  $app->dbx->migrations->migrate;
  $app->dbx->migrations->name('prodan')
    ->from_data(__PACKAGE__, 'resources/data/prodan_migrations.sql')->migrate();
  return $self;
}

# Deliverers are companies which deliver goods to users of our online shop.
# Such delivereres in Bulgaria are Econt, Speedy, Bulgarian Posts and others.
# Currently we integrate only Econt
my sub DELIVERERS {
  return qw(econt);
}

sub _configure_deliverers ($self, $conf) {
  for my $d (DELIVERERS) {
    my $d_sub = '_configure_' . $d;
    $self->$d_sub($conf);
  }
  return;
}

# The keys in the $conf hash reference are named after the examples given at
# http://delivery.econt.com/services/
sub _configure_econt ($self, $conf) {
  my $eco = $conf->{econt};

  # ID на магазина в "Достави с Еконт"
  $eco->{shop_id} //= 'demo';

  # Код за свързване
  $eco->{private_key} //= 'demo';

  # валута на магазина (валута на наложения платеж)
  $eco->{shop_currency} //= 'BGN';

  # URL визуализиращ форма за доставка
  $eco->{shippment_calc_url} //= 'https://delivery-demo.econt.com/customer_info.php';

  # Ендпойнта на услугата за създаване или редактиране на поръчка
  $eco->{crupdate_order_endpoint}
    //= 'https://delivery-demo.econt.com/services/OrdersService.updateOrder.json';

  # Ендпойнта на услугата за създаване или редактиране на товарителница
  $eco->{create_awb_endpoint}
    //= 'https://delivery-demo.econt.com/services/OrdersService.createAWB.json';

  # $self->app->debug($conf);
  $self->app->config->{shop} = $eco;
  return;
}

1;


=encoding utf8

=head1 NAME

Slovo::Plugin::Prodan - Make and manage sales in your Slovo-based site

=head1 SYNOPSIS

  # In slovo.conf
  load_plugins => [
    #...
    'Themes::Malka',
    {
      Prodan => {
        migrate  => 1,
        consents => {
          gdpr_url    => '/ѿносно/условия.bg.html',
          phone_url           => $ENV{SLOVO_PRODAN_PHONE_URL},
          delivery_prices_url => '/ѿносно/цени-доставки.bg.html',
        },
        econt => {
          shop_id                 => $ENV{SLOVO_PRODAN_SHOP_ID},
          private_key             => $ENV{SLOVO_PRODAN_PRIVATE_KEY},
          shippment_calc_url      => 'https://delivery.econt.com/customer_info.php',
          crupdate_order_endpoint =>
            'https://delivery.econt.com/services/OrdersService.updateOrder.json',
          create_awb_endpoint =>
            'https://delivery.econt.com/services/OrdersService.createAWB.json'
        }}
    },
    #...
  ],

=head1 DESCRIPTION

The word про̀дан (прода̀жба) in Bulgarian means sale. Roots are found in Old
Common Slavic (Old Bulgarian) I<проданьѥ>. Here is an exerpt from Codex
Suprasliensis(331.27) where this word was witnessed: I<сꙑнъ божии. вол҄еѭ
на сьпасьнѫѭ страсть съ вами придетъ. и на B<продании> станетъ.
искѹпѹѭштааго животворьноѭ кръвьѭ. своеѭ миръ.>

L<Slovo::Plugin::Prodan> is a L<Mojolicious::Plugin> that extends a
Slovo-based site and turns it into an online shop. 

=head1 FEATURES

In this edition of L<Slovo::Plugin::Prodan> we implement the following features:

=head2 A Shopping cart

A jQuery and localStorage based shopping cart. Two static files contain
the implementation and they can be inflated. The files are
C</css/cart.css> and C</js/cart.js>. You should inflate these files into
your public forlder C<domove/example.com/public> for the domain on which you
will use it. Even not inflated these will be referred from any page of the
site. The site layout C<layouts/site.html.ep> includes automatically these
two static files if this plugin is loaded.

  # Inflate new static files from Slovo::Plugin::Prodan
  bin/slovo inflate --class Slovo::Plugin::Prodan -p --path domove/xn--b1arjbl.xn--90ae/public

To add a product to your cart and make an order, you need a button, containing
the product data. For example:

    <button class="primary sharer button add-to-cart"
        title="книжно издание" data-sku="9786199169001" 
        data-title="Житие на света Петка Българска от свети патриарх Евтимий"
        data-weight="0.5" data-price="7.00"><img
        src="/css/malka/book-open-page-variant-outline.svg">
        <img src="/img/cart-plus-white.svg"></button>

See "A template..." below.

=head2 Delivery of sold goods

A "Pay on delivery" integration with Bulgarian currier L<Econt (in
Bulgarian)|https://www.econt.com/developers/43-kakvo-e-dostavi-s-ekont.html>.

=head2 Products

Products - a products SQL table to populate your pages with products. You
create a page with several articles (celini) in it. These celini will be the
web-pages for the products. You prepare a YAML file with products. Each product



( run in 2.763 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )