Git Product home page Git Product logo

shopctrl's Introduction

ShopCtrl

Use this client to convieniently interact with ShopCtrl. This PHP package was developed by Afosto to make a reliable connection between Afosto (Retail Software) and ShopCtrl and provides the following functionality:

  • get product data from ShopCtrl
  • get order data from ShopCtrl
  • create new orders at ShopCtrl

Getting Started

Simply follow the installation instructions. You will need an account at ShopCtrl that is set up for you to use.

Prerequisites

What things you need to install the software and how to install them

  • PHP5.5+
  • Composer (for installation)

Installing

Installing is easy through Composer.

composer require afosto/shopctrl

Examples

Now, to fetch productdata from ShopCtrl use the following code.

First set some configuration parameters:

$settings = new Settings();

Define the settings with data obtained from ShopCtrl

$settings->shopId = '';
$settings->baseUrl = '';
$settings->username = '';
$settings->password = '';
$settings->cultureId = '';

Initialze the application:

App::init($settings);

Get a product (from shop context)

Run a foreach for ProductSelections to get shop-context-related data and the full product that belongs to the productSelection data

foreach (ProductSelection::model()->findAll() as $productSelection) {
    $product = Product::model()->find($productSelection->productId);
    
    //Use the product data
    dump($productSelection, $product);
}

Generate an order

To create an order use the following sample. First set the contact data.

$contact = new ContactInfo();
$contact->streetAddress = 'Grondzijl';
$contact->streetAddressNumber = 16;
$contact->city = 'Groningen';
$contact->countryCode = 'NL';
$contact->companyName = 'Afosto SaaS BV';
$contact->eMail = '[email protected]';
$contact->firstName = 'Peter';
$contact->lastName = 'Bakker';
$contact->postalCode = '9731DG';
$contact->phone = '0507119519';

Create an order row.

$orderRow = new OrderRow();
$orderRow->orderRowKey = 1;
$orderRow->itemQuantity = 1;
$orderRow->productName = 'TestProduct';
$orderRow->productCode = 'ProductSku';
$orderRow->productDescription = 'Description test product';
$orderRow->itemPriceIncVat = 5.00;
$orderRow->rowDiscountIncVat = 0;
$orderRow->vatperc = 21;
$orderRow->rowTotalIncVat = 5;

Create an order.

$order = new Order();
$order->id = 0;
$order->shipToContact = $contact;
$order->billToContact = $contact;
$order->date = (new DateTime())->format('Y/m/d H:i:s');
$order->viewModusIncVAT = true;
$order->paymentFeeIncVat = 0;
$order->shippingCostsIncVat = 0;
$order->customerNote = '';
$order->syncSource = 'Afosto';
$order->discountIncVat = 0;
$order->orderRows[] = $orderRow;
$order->orderCode = 'test' . time();
$order->orderTotalIncVat = 5.00;
$order->currencyId = 1;
$order->currencyCode = 'EUR';

Set some specific data for the order based on the context / settings

$order->paymentTypeId = App::getInstance()->getSettings()->getPaymentTypeId('iDeal');
$order->cultureId = App::getInstance()->getSetting('cultureId');
$order->shopId = App::getInstance()->getSetting('shopId');
$order->mainStatusId = App::getInstance()->getSettings()->getOrderStatus('Active');

Now create the order

$order->create();

Now use the new data (model is updated with the results from the server)

$order->id;

Other examples

In the examples directory you will find more examples of this project.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the Apache License 2.0 - see the LICENSE.md file for details

shopctrl's People

Contributors

bakkerpeter avatar terraskye avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

dionscheper

shopctrl's Issues

Can't use Order::model()->find($orderId);

When I try to request the data for one specific order I get the following error:

An uncaught Exception was encountered
Type: Afosto\Bp\Exceptions\ValidationException
Message: Model Afosto\ShopCtrl\Models\int not found
Filename: vendor/afosto/bp/src/Components/Validator.php
Line Number: 149

Backtrace:
File: vendor/afosto/bp/src/Components/Model.php
Line: 148
Function: getNewModel

File: vendor/afosto/shopctrl/src/Models/Order.php
Line: 188
Function: setAttributes

File: vendor/afosto/shopctrl/src/Components/Operations/Find.php
Line: 44
Function: setAttributes

I have tried to fix the error myself but I have to admit that I am having trouble understanding how the code is intertwined. This error (presumably) also prevents me from getting all order information when I use Order::model()->findAll(). Only the following attributes get retrieved correctly

  ["id"]=>
  int(118955)
  ["orderCode"]=>
  string(14) "test1530020452"
  ["date"]=>
  string(19) "2018-06-26T15:40:52"
  ["orderTotalIncVat"]=>
  float(5)
  ["orderTotalExVat"]=>
  float(0)
  ["currencyId"]=>
  int(0)
  ["currencyCode"]=>
  string(3) "EUR"
  ["deleted"]=>
  bool(false)
  ["changeTimestamp"]=>
  string(23) "2018-06-26T15:40:54.497"
  ["mainStatusId"]=>
  int(1)
  ["affiliateId"]=>
  NULL

All other possible order attributes are NULL. Can you help me fix this error? (I assume that this also effects your own business negatively.) Or am I just doing something wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.