1
0
Fork 0
mirror of synced 2025-04-04 21:53:34 +03:00

Compare commits

...

40 commits

Author SHA1 Message Date
Eugene Polozov
d7d1cc0d46 The module is marked as deprecated 2021-03-26 15:45:40 +03:00
opheugene
7b21d2c66b
Move to Github Actions 2021-01-30 15:37:57 +03:00
Eugene Polozov
b0d1b7c9fb Change version in magento composer 2020-12-23 15:59:43 +03:00
opheugene
2fb72e4fc0
Rebranding RetailCRM, fix tests 2020-12-23 15:27:23 +03:00
Eugene Polozov
f50a102cc8 Rebranding RetailCRM, fix tests 2020-12-23 10:54:39 +03:00
Akolzin Dmitry
e62591895d
update travis config (#32) 2020-05-18 16:34:25 +03:00
Evgeniy-Goroh
97a9e8b27c
Save config dinamic fields
* save config dinamic fields
* update test
2020-05-18 12:19:01 +03:00
Alex Lushpai
ae03c8c881
Remove unnecessary code
fixes #30
2020-04-16 12:04:10 +03:00
gorokh
966406a609 issues #30 removed unnecessary code 2020-04-07 18:16:09 +03:00
Alex Lushpai
c2c2fa0a95
Merge pull request #28 from Evgeniy-Goroh/master
fix test
2019-10-24 10:49:29 +03:00
gorokh
65e44090de fix test 2019-10-21 14:50:06 +03:00
Alex Lushpai
a314a47d70
Merge pull request #27 from gwinn/master
fix version & travis config
2019-10-17 15:08:23 +03:00
Alex Lushpai
cd1061dfd1 update php version for travis 2019-10-17 14:23:19 +03:00
Alex Lushpai
033817af84 fix version & travis config 2019-10-17 13:40:32 +03:00
Alex Lushpai
4e9c9c087e
Merge pull request #26 from Evgeniy-Goroh/master
Поддержка функции добавления одинакового товара в заказ как разные позиции
2019-10-17 13:36:05 +03:00
Alex Lushpai
43c3e5be80
Merge branch 'master' into master 2019-10-17 13:35:30 +03:00
Alex Lushpai
227b0eb827
Update .travis.yml 2019-10-17 13:15:24 +03:00
Alex Lushpai
56deb86d1c
Update VERSION 2019-10-17 13:11:00 +03:00
Alex Lushpai
2756b8e797
Update CHACNGELOG.md 2019-10-17 13:10:42 +03:00
Alex Lushpai
99ff83c83c
Update .travis.yml 2019-10-17 13:09:47 +03:00
gorokh
fc1e208b08 fix price 2019-10-01 14:40:42 +03:00
gorokh
06ddf9a807 Поддержка функции добавления одинакового товара в заказ как разные товарные позиции из CRM 2019-09-26 16:39:02 +03:00
Alex Lushpai
23602a7b71
Merge pull request #25 from iyzoer/master
Delete duplicate injection
2019-05-07 11:50:59 +03:00
Akolzin Dmitry
7b3b49e563 Fix test 2019-03-21 10:37:20 +03:00
Akolzin Dmitry
2ed36df9f1 Delete duplicate injection 2019-03-21 10:10:55 +03:00
Alex Lushpai
6e9629efef
Merge pull request #22 from sergeygw1990/master
v2.4.1
2019-02-14 13:23:14 +03:00
Sergey
3b97a7f06c v2.4.1 2019-02-12 15:35:53 +03:00
Alex Lushpai
fd2524b207
Merge pull request #21 from iyzoer/master
Fixes for marketplace
2019-01-24 16:11:07 +03:00
Akolzin Dmitry
ccb1a6e77d Fixes for marketplace 2019-01-24 16:01:09 +03:00
Alex Lushpai
86124b1978
Merge pull request #20 from sergeygw1990/master
v2.4.0
2019-01-24 14:33:56 +03:00
Sergey
950f00ac5c fix version change in composer.json 2019-01-24 13:40:33 +03:00
Sergey
6f47b16cbd fix Add constant inventories in src/Helper/Data.php 2019-01-24 12:34:09 +03:00
Sergey
a6d80bf154 v2.4.0 2019-01-24 11:39:40 +03:00
Alex Lushpai
b15f8ec5a8
Merge pull request #19 from iyzoer/master
Изменена логика передачи данных по заказам и клиентам
2019-01-23 13:46:36 +03:00
Akolzin Dmitry
2c8a87c582 Добавлены настройки Daemon Collector 2019-01-22 10:00:52 +03:00
Akolzin Dmitry
f4eca5a7b0 Изменена логика передачи данных по заказам и клиентам 2019-01-18 11:46:10 +03:00
Alex Lushpai
6dd54014ae
Merge pull request #18 from iyzoer/master
Выгрузка габаритов и веса в ICML
2019-01-16 10:36:27 +03:00
Akolzin Dmitry
6e66eb3aea Выгрузка габаритов и веса в ICML 2019-01-15 14:13:20 +03:00
Alex Lushpai
23bfe5c6fb
Merge pull request #17 from iyzoer/master
v2.3.2
2018-12-25 15:34:06 +03:00
Akolzin Dmitry
09090fdd5f v2.3.2 2018-12-25 15:07:54 +03:00
68 changed files with 2291 additions and 275 deletions

234
.github/workflows/magento.yml vendored Normal file
View file

@ -0,0 +1,234 @@
# This is a basic workflow to help you get started with Actions
name: magento
on:
push:
branches:
- '**'
tags-ignore:
- '*.*'
pull_request:
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- php-version: '7.0'
branch: '2.0.2'
coverage: 1
- php-version: '7.0'
branch: '2.0.4'
- php-version: '7.0'
branch: '2.0.5'
- php-version: '7.0'
branch: '2.0.6'
- php-version: '7.0'
branch: '2.0.7'
- php-version: '7.0'
branch: '2.0.8'
- php-version: '7.0'
branch: '2.0.9'
- php-version: '7.0'
branch: '2.0.10'
- php-version: '7.0'
branch: '2.0.11'
- php-version: '7.0'
branch: '2.0.12'
- php-version: '7.0'
branch: '2.0.13'
- php-version: '7.0'
branch: '2.0.14'
- php-version: '7.0'
branch: '2.0.15'
- php-version: '7.0'
branch: '2.0.16'
- php-version: '7.0'
branch: '2.0.17'
- php-version: '7.0'
branch: '2.0.18'
- php-version: '7.0'
branch: '2.1.0'
- php-version: '7.0'
branch: '2.1.1'
- php-version: '7.0'
branch: '2.1.2'
- php-version: '7.0'
branch: '2.1.3'
- php-version: '7.0'
branch: '2.1.4'
- php-version: '7.0'
branch: '2.1.5'
- php-version: '7.0'
branch: '2.1.6'
- php-version: '7.0'
branch: '2.1.7'
- php-version: '7.0'
branch: '2.1.8'
- php-version: '7.0'
branch: '2.1.9'
- php-version: '7.0'
branch: '2.1.10'
- php-version: '7.0'
branch: '2.1.11'
- php-version: '7.0'
branch: '2.1.12'
- php-version: '7.0'
branch: '2.1.13'
- php-version: '7.0'
branch: '2.1.14'
- php-version: '7.0'
branch: '2.1.15'
- php-version: '7.0'
branch: '2.1.16'
- php-version: '7.1'
branch: '2.1.16'
- php-version: '7.0'
branch: '2.1.17'
- php-version: '7.1'
branch: '2.1.17'
- php-version: '7.0'
branch: '2.1.18'
- php-version: '7.1'
branch: '2.1.18'
- php-version: '7.0'
branch: '2.2.0'
- php-version: '7.1'
branch: '2.2.0'
- php-version: '7.0'
branch: '2.2.1'
- php-version: '7.1'
branch: '2.2.1'
- php-version: '7.0'
branch: '2.2.2'
- php-version: '7.1'
branch: '2.2.2'
- php-version: '7.0'
branch: '2.2.3'
- php-version: '7.1'
branch: '2.2.3'
- php-version: '7.0'
branch: '2.2.4'
- php-version: '7.1'
branch: '2.2.4'
- php-version: '7.0'
branch: '2.2.5'
- php-version: '7.1'
branch: '2.2.5'
- php-version: '7.0'
branch: '2.2.6'
- php-version: '7.1'
branch: '2.2.6'
- php-version: '7.0'
branch: '2.2.7'
- php-version: '7.1'
branch: '2.2.7'
- php-version: '7.0'
branch: '2.2.8'
- php-version: '7.1'
branch: '2.2.8'
- php-version: '7.0'
branch: '2.2.9'
- php-version: '7.1'
branch: '2.2.9'
- php-version: '7.0'
branch: '2.2.10'
- php-version: '7.1'
branch: '2.2.10'
services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: root
ports:
- 3306/tcp
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5
steps:
- uses: actions/checkout@v2
- name: Setup PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: xdebug
tools: composer:v1, phpunit:6.4.3
extensions: gd, mbstring, zip, mcrypt, pdo_mysql, dom, soap, bcmath
- name: Start mysql service
run: sudo /etc/init.d/mysql start
- name: Status mysql service
run: sudo systemctl status mysql
- name: Install Magento
env:
BRANCH: ${{ matrix.branch }}
PUBLIC_KEY: ${{ secrets.PUBLIC_KEY}}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY}}
run: make before_script
- name: Run tests
run: make test
- name: Coverage
env:
COVERAGE: ${{ matrix.coverage }}
if: env.COVERAGE == 1
run: |
make coverage
bash <(curl -s https://codecov.io/bash)
deploy:
needs: ['test']
if: success() && github.event_name == 'push' && github.repository_owner == 'retailcrm' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup PHP 7.2
uses: shivammathur/setup-php@v2
with:
php-version: '7.2'
tools: composer:v1
- name: Build release
run: |
git fetch origin --unshallow --tags
export LAST_TAG=`git describe --abbrev=0 --tags`
export VERSION=`cat VERSION`
export ARCHIVE_NAME=retailcrm-$VERSION.ocmod.zip
export ARCHIVE_PATH="/tmp/$ARCHIVE_NAME"
export RELEASE_TAG=v$VERSION
export LAST_COMMIT=`git log --oneline --format=%B -n 1 HEAD | head -n 1`
echo RELEASE_TAG=$RELEASE_TAG >> $GITHUB_ENV
echo LAST_TAG=$LAST_TAG >> $GITHUB_ENV
echo LAST_COMMIT=$LAST_COMMIT >> $GITHUB_ENV
echo ARCHIVE_PATH=$ARCHIVE_PATH >> $GITHUB_ENV
echo ARCHIVE_NAME=$ARCHIVE_NAME >> $GITHUB_ENV
make build_archive
- name: Create Release
id: create_release
uses: actions/create-release@v1
if: env.LAST_TAG != env.RELEASE_TAG
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
with:
tag_name: ${{ env.RELEASE_TAG }}
release_name: ${{ env.RELEASE_TAG }}
body: ${{ env.LAST_COMMIT }}
draft: false
prerelease: false
- name: Cleanup
if: env.LAST_TAG != env.RELEASE_TAG
run: make delete_archive

3
.gitignore vendored
View file

@ -1 +1,2 @@
/nbproject/private/
/nbproject/private/
.idea

View file

@ -1,40 +0,0 @@
language: php
sudo: false
env:
global:
- DB_USER=root
- DB_HOST=localhost
- DB_NAME=magento2_test
- ADMIN_FIRSTNAME=admin_firstname
- ADMIN_LASTNAME=admin_lastname
- ADMIN_EMAIL=example@email.com
- ADMIN_USER=admin
- ADMIN_PASS=admin123
matrix:
include:
- php: 7.0
env: BRANCH=2.2-develop
- php: 7.1
env: BRANCH=2.2-develop
- php: 7.1
env: BRANCH=2.3-develop
- php: 7.2
env: BRANCH=2.3-develop
before_script:
- bash bin/install.sh
script:
- bash bin/script.sh
deploy:
skip_cleanup: true
provider: script
script: make
on:
php: 7.2
branch: master
condition: "$DEPLOY = true"

View file

@ -1,5 +1,23 @@
## 2021-01-30 v.2.5.2
* Переход на GitHub Actions
## 2020-12-17 v.2.5.1
* Ребрендинг RetailCRM
## 2018-12-25 v.2.5.0
* Поддержка передачи в заказе нескольких позиций одного товара
## 2018-12-25 v.2.4.1
* Удалена генерация externalId покупателя при заказе от незарегестрированного пользователя
## 2018-12-25 v.2.4.0
* Добавлен функционал получения остатков из RetailCRM
## 2018-12-25 v.2.3.2
* Добавлена выгрузка картинок категорий товаров в ICML
## 2018-10-25 v.2.3.1
* Добавлена активация модуля в маркетплейсе retailCRM
* Добавлена активация модуля в маркетплейсе RetailCRM
## 2018-08-21 v.2.3.0
* Добавлены консольные команды для выгрузки архива клиентов и заказов
@ -9,4 +27,4 @@
* При формировании каталога выгружаются выбранные атрибуты товаров
* Улучшена выгрузка товаров в заказе (теперь учитываются конфигурируемые товары)
* Добавлены переводы на русский и испанский языки
* Из обработки истории удален менеджер объектов
* Из обработки истории удален менеджер объектов

View file

@ -1,14 +1,24 @@
FILE = $(TRAVIS_BUILD_DIR)/VERSION
export ROOT_DIR=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
VERSION = `cat $(FILE)`
ARCHIVE_NAME = '/tmp/retailcrm-retailcrm-'$(VERSION)'.zip'
MAGE_ROOT=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/../magento2
all: build_archive send_to_ftp delete_archive
.PHONY: build_archive delete_archive
build_archive:
cd src; zip -r $(ARCHIVE_NAME) ./*
send_to_ftp:
curl -T $(ARCHIVE_NAME) -u $(FTP_USER):$(FTP_PASSWORD) ftp://$(FTP_HOST)
delete_archive:
rm -f $(ARCHIVE_NAME)
test:
mkdir coverage
php $(MAGE_ROOT)/vendor/phpunit/phpunit/phpunit -c $(MAGE_ROOT)/dev/tests/unit/phpunit.xml.dist $(MAGE_ROOT)/app/code/Retailcrm/Retailcrm/Test/Unit
before_script:
bash bin/install.sh
coverage:
wget https://phar.phpunit.de/phpcov-2.0.2.phar && php phpcov-2.0.2.phar merge coverage/ --clover coverage.xml

View file

@ -1,17 +1,21 @@
[![Build Status](https://img.shields.io/travis/retailcrm/magento-module/master.svg?style=flat-square)](https://travis-ci.org/retailcrm/magento-module)
[![GitHub release](https://img.shields.io/github/release/retailcrm/magento-module.svg?style=flat-square)](https://github.com/retailcrm/magento-module/releases)
[![No Maintenance Intended](http://unmaintained.tech/badge.svg)](http://unmaintained.tech/)
[![Build Status](https://github.com/retailcrm/magento-module/workflows/magento/badge.svg)](https://github.com/retailcrm/magento-module/actions)
[![Coverage](https://img.shields.io/codecov/c/gh/retailcrm/magento-module/master.svg?logo=github)](https://codecov.io/gh/retailcrm/magento-module)
[![GitHub release](https://img.shields.io/github/release/retailcrm/magento-module.svg?logo=codecov)](https://github.com/retailcrm/magento-module/)
[![PHP version](https://img.shields.io/badge/PHP->=5.6-blue.svg?style=flat-square)](https://php.net/)
Magento module
DEPRECATED Magento module
==============
Magento 2 module for interaction with [retailCRM](http://www.retailcrm.ru).
**The module is deprecated and no longer supported**
Magento 2 module for interaction with [RetailCRM](http://www.retailcrm.ru) ([Documentation](https://docs.retailcrm.pro/Users/Integration/SiteModules/Magento) page)
Module allows:
* Exchange the orders data with retailCRM
* Exchange the orders data with RetailCRM
* Configure relations between dictionaries of retailCRM and Magento (statuses, payments, delivery types and etc)
* Generate [ICML](http://www.retailcrm.ru/docs/Developers/ICML) (Intaro Markup Language) export file for catalog loading by retailCRM
* Generate [ICML](http://www.retailcrm.ru/docs/Developers/ICML) (Intaro Markup Language) export file for catalog loading by RetailCRM
## ICML
@ -29,4 +33,4 @@ By default ICML file is being generated by module every 4 hours. You can find fi
composer require retailcrm/api-client-php ~5.0
```
This module is compatible with Magento up to version 2.2.3
This module is compatible with Magento up to version 2.2.8

View file

@ -1,27 +1,18 @@
Magento module
DEPRECATED Magento module
Модуль Magento 2 для интеграции с [retailCRM](http://www.retailcrm.ru).
**Модуль устарел и больше не поддерживается**
Модуль Magento 2 для интеграции с [RetailCRM](http://www.retailcrm.ru) ([Документация](https://docs.retailcrm.ru/Users/Integration/SiteModules/Magento))
Модуль позволяет:
* Производить обмен заказами с retailCRM
* Настроить соответствие справочников retailCRM и Magento (статусы, оплаты, типы доставки и т.д.)
* Создать [ICML](http://www.retailcrm.ru/docs/Developers/ICML) (Intaro Markup Language) для загрузки каталога товаров в retailCRM
### ICML
По умолчанию ICML-файл генерируется модулем каждые 4 часа. Вы можете найти файл в корневой директории с именем «retailcrm_{{shop_code}}.xml". Например, http://example.org/retailcrm_default.xml
### Ручная установка
1) Находясь в корневой директории проекта выполните команду:
* Настроить соответствие справочников retailCRM и Magento (статусы, оплаты, типы доставки и т.д.)
* Создать [ICML] (http://www.retailcrm.ru/docs/Developers/ICML) (Intaro Markup Language) для загрузки каталога товаров в RetailCRM
* Производить обмен заказами с RetailCRM
* Настроить соответствие справочников RetailCRM и Magento (статусы, оплаты, типы доставки и т.д.)
* Создать [ICML](http://www.retailcrm.ru/docs/Developers/ICML) (Intaro Markup Language) для загрузки каталога товаров в RetailCRM
## ICML
По умолчанию ICML-файл генерируется модулем каждые 4 часа. Вы можете найти файл в корневой папке с именем «retailcrm_{{shop_code}}.xml". Например, http://retailcrm.ru/retailcrm_default.xml
По умолчанию ICML-файл генерируется модулем каждые 4 часа. Вы можете найти файл в корневой папке с именем «retailcrm_{{shop_code}}.xml". Например, http://example.ru/retailcrm_default.xml
## Ручная установка
@ -36,4 +27,4 @@ composer require retailcrm/api-client-php ~5.0
В конфигурационный файл `composer.json` вашего проекта будет добавлена библиотека [retailcrm/api-client-php](https://github.com/retailcrm/api-client-php), которая будет установлена в директорию `vendor/`.
Этот модуль совместим с Magento 2 до версии 2.2.3
Этот модуль совместим с Magento 2 до версии 2.2.8

View file

@ -1 +1 @@
2.3.1
2.5.2

View file

@ -1,13 +1,13 @@
#!/usr/bin/env bash
if [ -z $TRAVIS_BUILD_DIR ]; then
if [ -z $ROOT_DIR ]; then
exit 0;
fi
MAGE_ROOT=$TRAVIS_BUILD_DIR/../magento2
MAGE_ROOT=$ROOT_DIR/../magento2
create_db() {
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"
mysqladmin create "magento2_test" --user="root" --password="root"
}
magento_clone() {
@ -15,22 +15,38 @@ magento_clone() {
git clone https://github.com/magento/magento2
cd magento2
git checkout $BRANCH
composer install
touch auth.json
echo '
{
"http-basic": {
"repo.magento.com": {
"username": "<public-key>",
"password": "<private-key>"
}
}
}
' > auth.json
sudo sed -e "s?<public-key>?$PUBLIC_KEY?g" --in-place auth.json
sudo sed -e "s?<private-key>?$PRIVATE_KEY?g" --in-place auth.json
composer install --no-interaction --prefer-dist
composer require retailcrm/api-client-php
}
magento_install() {
cd $MAGE_ROOT
php bin/magento setup:install \
--db-host="$DB_HOST" \
--db-name="$DB_NAME" \
--db-user="$DB_USER" \
--admin-firstname="$ADMIN_FIRSTNAME" \
--admin-lastname="$ADMIN_LASTNAME" \
--admin-email="$ADMIN_EMAIL" \
--admin-user="$ADMIN_USER" \
--admin-password="$ADMIN_PASS" \
--db-host="localhost" \
--db-name="magento2_test" \
--db-user="root" \
--db-password="root" \
--admin-firstname="admin_firstname" \
--admin-lastname="admin_lastname" \
--admin-email="example@email.com" \
--admin-user="admin" \
--admin-password="admin123" \
--language="en_US" \
--currency="USD" \
--timezone="Europe/Moscow"
@ -39,7 +55,7 @@ magento_install() {
module_install() {
cd $MAGE_ROOT
mkdir -p app/code/Retailcrm/Retailcrm
cp -R $TRAVIS_BUILD_DIR/src/* app/code/Retailcrm/Retailcrm
cp -R $ROOT_DIR/src/* app/code/Retailcrm/Retailcrm
php bin/magento module:enable Retailcrm_Retailcrm
php bin/magento setup:upgrade

View file

@ -1,9 +0,0 @@
#!/usr/bin/env bash
if [ -z $TRAVIS_BUILD_DIR ]; then
exit 0;
fi
MAGE_ROOT=$TRAVIS_BUILD_DIR/../magento2
cd $MAGE_ROOT
php vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/Retailcrm/Retailcrm/Test/Unit

View file

@ -82,7 +82,6 @@ class Payment extends \Magento\Config\Block\System\Config\Form\Fieldset
if ($this->client->isConfigured()) {
$paymentMethods = $this->paymentConfig->getActiveMethods();
foreach ($paymentMethods as $code => $payment) {
$html .= $this->_getFieldHtml($element, $payment);
}
@ -117,7 +116,7 @@ class Payment extends \Magento\Config\Block\System\Config\Form\Fieldset
return $defaultValues;
}
if ($response->isSuccessful()) {
if (isset($response['paymentTypes']) && $response->isSuccessful()) {
$paymentsTypes = $response['paymentTypes'];
} else {
return $defaultValues;
@ -137,7 +136,7 @@ class Payment extends \Magento\Config\Block\System\Config\Form\Fieldset
* Get field html
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $fieldset
* @param \Magento\Payment\Model\Method\AbstractMethod $payment
* @param \Magento\Payment\Api\Data\PaymentMethodInterface $payment
*
* @return string
*/
@ -145,9 +144,7 @@ class Payment extends \Magento\Config\Block\System\Config\Form\Fieldset
{
$configData = $this->getConfigData();
$path = 'retailcrm/' . $fieldset->getId() . '/' . $payment->getCode();
$data = isset($configData[$path]) ? $configData[$path] : [];
$e = $this->_getDummyElement();
$field = $fieldset->addField(

View file

@ -0,0 +1,95 @@
<?php
namespace Retailcrm\Retailcrm\Block\Adminhtml\System\Config\Form\Fieldset;
class PaymentList extends \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
{
/**
* @var $_paymentCms \Retailcrm\Retailcrm\Model\Config\Backend\PaymentCms
*/
protected $_paymentCms;
/**
* @var $_paymentCrm \Retailcrm\Retailcrm\Model\Config\Backend\PaymentCrm
*/
protected $_paymentCrm;
/**
* @return \Magento\Framework\View\Element\BlockInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _getPaymentCmsRenderer()
{
if (!$this->_paymentCms) {
$this->_paymentCms = $this->getLayout()->createBlock(
'\Retailcrm\Retailcrm\Model\Config\Backend\PaymentCms',
'',
['data' => ['is_render_to_js_template' => true]]
);
}
return $this->_paymentCms;
}
/**
* @return \Magento\Framework\View\Element\BlockInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _getPaymentCrmRenderer()
{
if (!$this->_paymentCrm) {
$this->_paymentCrm = $this->getLayout()->createBlock(
'\Retailcrm\Retailcrm\Model\Config\Backend\PaymentCrm',
'',
['data' => ['is_render_to_js_template' => true]]
);
}
return $this->_paymentCrm;
}
/**
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _prepareToRender()
{
$this->addColumn(
'payment_cms',
[
'label' => __('CMS'),
'renderer' => $this->_getPaymentCmsRenderer()
]
);
$this->addColumn(
'payment_crm',
[
'label' => __('CRM'),
'renderer' => $this->_getPaymentCrmRenderer()
]
);
$this->_addAfter = false;
$this->_addButtonLabel = __('Add');
}
/**
*
* @param \Magento\Framework\DataObject $row
* @throws \Magento\Framework\Exception\LocalizedException
* @return void
*/
protected function _prepareArrayRow(\Magento\Framework\DataObject $row)
{
$options = [];
$customAttribute = $row->getData('payment_cms');
$key = 'option_' . $this->_getPaymentCmsRenderer()->calcOptionHash($customAttribute);
$options[$key] = 'selected="selected"';
$customAttribute = $row->getData('payment_crm');
$key = 'option_' . $this->_getPaymentCrmRenderer()->calcOptionHash($customAttribute);
$options[$key] = 'selected="selected"';
$row->setData('option_extra_attrs', $options);
}
}

View file

@ -117,13 +117,17 @@ class Shipping extends \Magento\Config\Block\System\Config\Form\Fieldset
$values = [];
$response = $this->client->deliveryTypesList();
try {
$response = $this->client->deliveryTypesList();
} catch (\Exception $exception) {
return $defaultValues;
}
if ($response === false) {
return $defaultValues;
}
if ($response->isSuccessful()) {
if (isset($response['deliveryTypes']) && $response->isSuccessful()) {
$deliveryTypes = $response['deliveryTypes'];
} else {
return $defaultValues;

View file

@ -0,0 +1,95 @@
<?php
namespace Retailcrm\Retailcrm\Block\Adminhtml\System\Config\Form\Fieldset;
class ShippingList extends \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
{
/**
* @var $_shippingCms \Retailcrm\Retailcrm\Model\Config\Backend\ShippingCms
*/
protected $_shippingCms;
/**
* @var $_shippingCrm \Retailcrm\Retailcrm\Model\Config\Backend\ShippingCrm
*/
protected $_shippingCrm;
/**
* @return \Magento\Framework\View\Element\BlockInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _getShippingCmsRenderer()
{
if (!$this->_shippingCms) {
$this->_shippingCms = $this->getLayout()->createBlock(
'\Retailcrm\Retailcrm\Model\Config\Backend\ShippingCms',
'',
['data' => ['is_render_to_js_template' => true]]
);
}
return $this->_shippingCms;
}
/**
* @return \Magento\Framework\View\Element\BlockInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _getShippingCrmRenderer()
{
if (!$this->_shippingCrm) {
$this->_shippingCrm = $this->getLayout()->createBlock(
'\Retailcrm\Retailcrm\Model\Config\Backend\ShippingCrm',
'',
['data' => ['is_render_to_js_template' => true]]
);
}
return $this->_shippingCrm;
}
/**
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _prepareToRender()
{
$this->addColumn(
'shipping_cms',
[
'label' => __('CMS'),
'renderer' => $this->_getShippingCmsRenderer()
]
);
$this->addColumn(
'shipping_crm',
[
'label' => __('CRM'),
'renderer' => $this->_getShippingCrmRenderer()
]
);
$this->_addAfter = false;
$this->_addButtonLabel = __('Add');
}
/**
*
* @param \Magento\Framework\DataObject $row
* @throws \Magento\Framework\Exception\LocalizedException
* @return void
*/
protected function _prepareArrayRow(\Magento\Framework\DataObject $row)
{
$options = [];
$customAttribute = $row->getData('shipping_cms');
$key = 'option_' . $this->_getShippingCmsRenderer()->calcOptionHash($customAttribute);
$options[$key] = 'selected="selected"';
$customAttribute = $row->getData('shipping_crm');
$key = 'option_' . $this->_getShippingCrmRenderer()->calcOptionHash($customAttribute);
$options[$key] = 'selected="selected"';
$row->setData('option_extra_attrs', $options);
}
}

View file

@ -109,13 +109,17 @@ class Site extends \Magento\Config\Block\System\Config\Form\Fieldset
$values = [];
$response = $this->client->sitesList();
try {
$response = $this->client->sitesList();
} catch (\Exception $exception) {
return $defaultValues;
}
if ($response === false) {
return $defaultValues;
}
if ($response->isSuccessful()) {
if (isset($response['sites']) && $response->isSuccessful()) {
$sites = $response['sites'];
} else {
return $defaultValues;

View file

@ -115,13 +115,17 @@ class Sites extends \Magento\Config\Block\System\Config\Form\Fieldset
$values = [];
$response = $this->client->sitesList();
try {
$response = $this->client->sitesList();
} catch (\Exception $exception) {
return $defaultValues;
}
if ($response === false) {
return $defaultValues;
}
if ($response->isSuccessful()) {
if (isset($response['sites']) && $response->isSuccessful()) {
$sites = $response['sites'];
} else {
return $defaultValues;

View file

@ -111,13 +111,17 @@ class Status extends \Magento\Config\Block\System\Config\Form\Fieldset
$values = [];
$response = $this->client->statusesList();
try {
$response = $this->client->statusesList();
} catch (\Exception $exception) {
return $defaultValues;
}
if ($response === false) {
return $defaultValues;
}
if ($response->isSuccessful()) {
if (isset($response['statuses']) && $response->isSuccessful()) {
$statuses = $response['statuses'];
} else {
return $defaultValues;

View file

@ -0,0 +1,95 @@
<?php
namespace Retailcrm\Retailcrm\Block\Adminhtml\System\Config\Form\Fieldset;
class StatusList extends \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
{
/**
* @var $_statusCms \Retailcrm\Retailcrm\Model\Config\Backend\StatusCms
*/
protected $_statusCms;
/**
* @var $_statusCrm \Retailcrm\Retailcrm\Model\Config\Backend\StatusCrm
*/
protected $_statusCrm;
/**
* @return \Magento\Framework\View\Element\BlockInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _getStatusCmsRenderer()
{
if (!$this->_statusCms) {
$this->_statusCms = $this->getLayout()->createBlock(
'\Retailcrm\Retailcrm\Model\Config\Backend\StatusCms',
'',
['data' => ['is_render_to_js_template' => true]]
);
}
return $this->_statusCms;
}
/**
* @return \Magento\Framework\View\Element\BlockInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _getStatusCrmRenderer()
{
if (!$this->_statusCrm) {
$this->_statusCrm = $this->getLayout()->createBlock(
'\Retailcrm\Retailcrm\Model\Config\Backend\StatusCrm',
'',
['data' => ['is_render_to_js_template' => true]]
);
}
return $this->_statusCrm;
}
/**
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _prepareToRender()
{
$this->addColumn(
'status_cms',
[
'label' => __('CMS'),
'renderer' => $this->_getStatusCmsRenderer()
]
);
$this->addColumn(
'status_crm',
[
'label' => __('CRM'),
'renderer' => $this->_getStatusCrmRenderer()
]
);
$this->_addAfter = false;
$this->_addButtonLabel = __('Add');
}
/**
*
* @param \Magento\Framework\DataObject $row
* @throws \Magento\Framework\Exception\LocalizedException
* @return void
*/
protected function _prepareArrayRow(\Magento\Framework\DataObject $row)
{
$options = [];
$customAttribute = $row->getData('status_cms');
$key = 'option_' . $this->_getStatusCmsRenderer()->calcOptionHash($customAttribute);
$options[$key] = 'selected="selected"';
$customAttribute = $row->getData('status_crm');
$key = 'option_' . $this->_getStatusCrmRenderer()->calcOptionHash($customAttribute);
$options[$key] = 'selected="selected"';
$row->setData('option_extra_attrs', $options);
}
}

View file

@ -0,0 +1,85 @@
<?php
namespace Retailcrm\Retailcrm\Block\Frontend;
class DaemonCollector extends \Magento\Framework\View\Element\Template
{
private $customer;
private $helper;
private $storeResolver;
private $js = '';
private $template = <<<EOT
<script type="text/javascript">
(function(_,r,e,t,a,i,l){_['retailCRMObject']=a;_[a]=_[a]||function(){(_[a].q=_[a].q||[]).push(arguments)};_[a].l=1*new Date();l=r.getElementsByTagName(e)[0];i=r.createElement(e);i.async=!0;i.src=t;l.parentNode.insertBefore(i,l)})(window,document,'script','https://collector.retailcrm.pro/w.js','_rc');
{{ code }}
_rc('send', 'pageView');
</script>
EOT;
/**
* DaemonCollector constructor.
*
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Customer\Model\Session $customerSession
* @param \Magento\Store\Api\StoreResolverInterface $storeResolver
* @param \Retailcrm\Retailcrm\Helper\Data $helper
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Customer\Model\Session $customerSession,
\Magento\Store\Api\StoreResolverInterface $storeResolver,
\Retailcrm\Retailcrm\Helper\Data $helper,
array $data = []
) {
parent::__construct($context, $data);
$this->customer = $customerSession->getCustomer();
$this->storeResolver = $storeResolver;
$this->helper = $helper;
}
/**
* @return string
*/
public function getJs()
{
return $this->js;
}
/**
* @return $this
*/
public function buildScript()
{
$params = array();
if ($this->customer->getId()) {
$params['customerId'] = $this->customer->getId();
}
try {
$siteKey = $this->helper->getSiteKey(
$this->_storeManager->getStore(
$this->storeResolver->getCurrentStoreId()
)->getWebsiteId()
);
} catch (\Magento\Framework\Exception\NoSuchEntityException $entityException) {
return $this;
}
if ($siteKey) {
$this->js = preg_replace(
'/{{ code }}/',
sprintf(
"\t_rc('create', '%s', %s);\n",
$siteKey,
json_encode((object) $params)
),
$this->template
);
}
return $this;
}
}

View file

@ -44,7 +44,7 @@ class CustomersExport extends Command
protected function configure()
{
$this->setName('retailcrm:customers:export')
->setDescription('Upload archive customers to retailCRM from Magento')
->setDescription('Upload archive customers to RetailCRM from Magento')
->addArgument('from', InputArgument::OPTIONAL, 'Beginning order number')
->addArgument('to', InputArgument::OPTIONAL, 'End order number');
@ -52,14 +52,14 @@ class CustomersExport extends Command
}
/**
* Upload customers to retailCRM
* Upload customers to RetailCRM
*
* @param InputInterface $input
* @param OutputInterface $output
*
* @throws \Exception
*
* @return boolean
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
@ -89,7 +89,7 @@ class CustomersExport extends Command
if (empty($customers)) {
$output->writeln('<comment>Customers not found</comment>');
return false;
return 0;
}
/** @var \Magento\Customer\Model\Customer $customer */
@ -112,6 +112,6 @@ class CustomersExport extends Command
$output->writeln('<info>Uploading customers finished</info>');
return true;
return 0;
}
}

View file

@ -0,0 +1,79 @@
<?php
namespace Retailcrm\Retailcrm\Console\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
class IcmlGenerate extends Command
{
private $icml;
private $storeManager;
private $appState;
public function __construct(
\Retailcrm\Retailcrm\Model\Icml\Icml $icml,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\App\State $appState
) {
$this->icml = $icml;
$this->storeManager = $storeManager;
$this->appState = $appState;
parent::__construct();
}
protected function configure()
{
$this->setName('retailcrm:icml:generate')
->setDescription('Generating ICML catalog in root directory')
->addArgument('website', InputArgument::OPTIONAL, 'Website id');
parent::configure();
}
/**
* Generate ICML catalog
*
* @param InputInterface $input
* @param OutputInterface $output
*
* @throws \Exception
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->appState->setAreaCode(\Magento\Framework\App\Area::AREA_GLOBAL);
$arguments = $input->getArguments();
$websites = [];
if (isset($arguments['website'])) {
$websites[] = $this->storeManager->getWebsite($arguments['website']);
} else {
$websites = $this->storeManager->getWebsites();
}
if (!$websites) {
$output->writeln('<comment>Websites not found</comment>');
return 0;
}
foreach ($websites as $website) {
try {
$this->icml->generate($website);
} catch (\Exception $exception) {
$output->writeln('<comment>' . $exception->getMessage() . '</comment>');
return 1;
}
}
return 0;
}
}

View file

@ -37,7 +37,7 @@ class OrdersExport extends Command
protected function configure()
{
$this->setName('retailcrm:orders:export')
->setDescription('Upload archive orders to retailCRM from Magento')
->setDescription('Upload archive orders to RetailCRM from Magento')
->addArgument('from', InputArgument::OPTIONAL, 'Beginning order number')
->addArgument('to', InputArgument::OPTIONAL, 'End order number');
@ -45,7 +45,7 @@ class OrdersExport extends Command
}
/**
* Upload orders to retailCRM
* Upload orders to RetailCRM
*
* @param InputInterface $input
* @param OutputInterface $output

24
src/Cron/Inventories.php Normal file
View file

@ -0,0 +1,24 @@
<?php
namespace Retailcrm\Retailcrm\Cron;
class Inventories
{
private $inventoriesUpload;
private $helper;
public function __construct(
\Retailcrm\Retailcrm\Helper\Data $helper,
\Retailcrm\Retailcrm\Model\Service\InventoriesUpload $InventoriesUpload
) {
$this->helper = $helper;
$this->inventoriesUpload = $InventoriesUpload;
}
public function execute()
{
if ($this->helper->getInventoriesUpload() == true) {
$this->inventoriesUpload->uploadInventory();
}
}
}

View file

@ -2,6 +2,7 @@
namespace Retailcrm\Retailcrm\Helper;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\App\Helper\Context;
@ -14,6 +15,8 @@ class Data extends AbstractHelper
const XML_PATH_RETAILCRM = 'retailcrm/';
const XML_PATH_DEFAULT_SITE = 'retailcrm_site/default';
const XML_PATH_SITES = 'retailcrm_sites/';
const XML_PATH_DAEMON_COLLECTOR = 'daemon_collector/';
const XML_PATH_INVENTORIES = 'inventories_upload/';
public function __construct(
Context $context,
@ -45,6 +48,7 @@ class Data extends AbstractHelper
* @param $store
*
* @return mixed|null
* @throws \Exception
*/
public function getSite($store)
{
@ -70,6 +74,9 @@ class Data extends AbstractHelper
return $websitesConfig;
}
/**
* @return array
*/
public function getMappingSites()
{
$sites = [];
@ -90,6 +97,86 @@ class Data extends AbstractHelper
return $sites;
}
/**
* @param $website
*
* @return array|bool
*/
public function getDaemonCollector($website)
{
$forWebsite = $this->scopeConfig->getValue(
self::XML_PATH_RETAILCRM . self::XML_PATH_DAEMON_COLLECTOR . 'active',
ScopeInterface::SCOPE_WEBSITES,
$website
);
if ($forWebsite) {
return [
'website' => $website,
'active' => $forWebsite
];
}
$forDefault = $this->scopeConfig->getValue(
self::XML_PATH_RETAILCRM . self::XML_PATH_DAEMON_COLLECTOR . 'active',
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
);
if ($forDefault) {
return [
'website' => 0,
'active' => $forDefault
];
}
return false;
}
public function getInventoriesUpload()
{
$inventories = $this->scopeConfig->getValue(
self::XML_PATH_RETAILCRM . self::XML_PATH_INVENTORIES . 'active',
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
);
if ($inventories) {
return true;
}
return false;
}
/**
* @param $website
*
* @return bool|mixed
*/
public function getSiteKey($website)
{
$daemonCollector = $this->getDaemonCollector($website);
if ($daemonCollector === false) {
return false;
}
if ($daemonCollector['active']) {
if ($daemonCollector['website'] > 0) {
return $this->scopeConfig->getValue(
self::XML_PATH_RETAILCRM . self::XML_PATH_DAEMON_COLLECTOR . 'key',
ScopeInterface::SCOPE_WEBSITES,
$website
);
} else {
return $this->scopeConfig->getValue(
self::XML_PATH_RETAILCRM . self::XML_PATH_DAEMON_COLLECTOR . 'key',
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
);
}
}
return false;
}
/**
* Recursive array filter
*
@ -119,4 +206,63 @@ class Data extends AbstractHelper
return $haystack;
}
/**
* @return mixed
*/
public function getConfigPayments()
{
$json = $this->scopeConfig->getValue('retailcrm/paymentList/paymentList');
$List = $this->getConfigJsonUnserialize($json);
foreach ($List as $code => $el) {
$payments[$el['payment_cms']] = $el['payment_crm'];
}
return $payments;
}
/**
* @return mixed
*/
public function getCongigShipping()
{
$json = $this->scopeConfig->getValue('retailcrm/shippingList/shippingList');
$shippingList = $this->getConfigJsonUnserialize($json);
foreach ($shippingList as $code => $el) {
$shippings[$el['shipping_cms']] = $el['shipping_crm'];
}
return $shippings;
}
/**
* @return mixed
*/
public function getCongigStatus()
{
$json = $this->scopeConfig->getValue('retailcrm/statusList/statusList');
$List = $this->getConfigJsonUnserialize($json);
foreach ($List as $code => $el) {
$statusList[$el['status_cms']] = $el['status_crm'];
}
return $statusList;
}
/**
* @param $json
*
* @return mixed
*/
public function getConfigJsonUnserialize($json)
{
if (class_exists(\Magento\Framework\Serialize\Serializer\Json::class)) {
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$serializer = $objectManager->create(\Magento\Framework\Serialize\Serializer\Json::class);
return $serializer->unserialize($json);
} else {
return json_decode($json);
}
}
}

View file

@ -82,7 +82,7 @@ class ApiUrl extends \Magento\Framework\App\Config\Value
} elseif (!$response->isSuccessful() && $response['errorMsg'] == $api->getErrorText('errorApiKey')) {
throw new \Magento\Framework\Exception\ValidatorException(__('Incorrect API key'));
} elseif (isset($response['errorMsg']) && $response['errorMsg'] == $api->getErrorText('errorAccount')) {
throw new \Magento\Framework\Exception\ValidatorException(__('Incorrect URL of retailCRM'));
throw new \Magento\Framework\Exception\ValidatorException(__('Incorrect URL of RetailCRM'));
}
return true;

View file

@ -82,7 +82,7 @@ class ApiVersion extends \Magento\Framework\App\Config\Value
if ($response->isSuccessful()) {
$availableVersions = $response['versions'];
} else {
throw new \Magento\Framework\Exception\ValidatorException(__('Incorrect URL of retailCRM or API key'));
throw new \Magento\Framework\Exception\ValidatorException(__('Incorrect URL of RetailCRM or API key'));
}
if (isset($availableVersions)) {

View file

@ -0,0 +1,71 @@
<?php
namespace Retailcrm\Retailcrm\Model\Config\Backend;
class PaymentCms extends \Magento\Framework\View\Element\Html\Select
{
/**
* @var \Magento\Payment\Model\Config
*/
private $paymentConfig;
/**
* @var \Retailcrm\Retailcrm\Model\Logger\Logger
*/
private $logger;
/**
* PaymentCms constructor.
*
* @param \Magento\Framework\View\Element\Context $context
* @param \Magento\Payment\Model\Config $paymentConfig
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Context $context,
\Magento\Payment\Model\Config $paymentConfig,
\Retailcrm\Retailcrm\Model\Logger\Logger $logger,
array $data = []
) {
parent::__construct($context, $data);
$this->paymentConfig = $paymentConfig;
$this->logger = $logger;
}
/**
* @param string $value
* @return Magently\Tutorial\Block\Adminhtml\Form\Field\Activation
*/
public function setInputName($value)
{
return $this->setName($value);
}
/**
* Parse to html.
*
* @return mixed
*/
public function _toHtml()
{
if (!$this->getOptions()) {
$paymentMethods = array();
try {
$paymentMethods = $this->paymentConfig->getActiveMethods();
} catch (\Exception $exception) {
$this->logger->writeRow($exception->getMessage());
}
$this->addOption( 'null', "not selected");
if ($paymentMethods) {
foreach ($paymentMethods as $code => $payment) {
$this->addOption($payment->getCode(), $payment->getTitle());
}
}
}
return parent::_toHtml();
}
}

View file

@ -0,0 +1,75 @@
<?php
namespace Retailcrm\Retailcrm\Model\Config\Backend;
class PaymentCrm extends \Magento\Framework\View\Element\Html\Select
{
/**
* @var \Retailcrm\Retailcrm\Helper\Proxy
*/
private $client;
/**
* @var \Retailcrm\Retailcrm\Model\Logger\Logger
*/
private $logger;
/**
* Activation constructor.
*
* @param \Magento\Framework\View\Element\Context $context
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Context $context,
\Retailcrm\Retailcrm\Helper\Proxy $client,
\Retailcrm\Retailcrm\Model\Logger\Logger $logger,
array $data = []
) {
parent::__construct($context, $data);
$this->client = $client;
$this->logger = $logger;
}
/**
* @param string $value
* @return Magently\Tutorial\Block\Adminhtml\Form\Field\Activation
*/
public function setInputName($value)
{
return $this->setName($value);
}
/**
* Parse to html.
*
* @return mixed
*/
public function _toHtml()
{
if (!$this->getOptions()) {
$paymentsTypes = array();
try {
$response = $this->client->paymentTypesList();
} catch (\Exception $exception) {
$this->logger->writeRow($exception->getMessage());
}
if (isset($response) && $response->isSuccessful()) {
$paymentsTypes = $response['paymentTypes'];
}
$this->addOption( 'null', "not selected");
if ($paymentsTypes) {
foreach ($paymentsTypes as $paymentsType) {
$this->addOption($paymentsType['code'], $paymentsType['name']);
}
}
}
return parent::_toHtml();
}
}

View file

@ -0,0 +1,72 @@
<?php
namespace Retailcrm\Retailcrm\Model\Config\Backend;
class ShippingCms extends \Magento\Framework\View\Element\Html\Select
{
/**
* @var \Magento\Shipping\Model\Config
*/
private $shippingConfig;
/**
* @var \Retailcrm\Retailcrm\Model\Logger\Logger
*/
private $logger;
/**
* ShippingColumn constructor.
*
* @param \Magento\Framework\View\Element\Context $context
* @param \Magento\Shipping\Model\Config $shippingConfig
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Context $context,
\Magento\Shipping\Model\Config $shippingConfig,
\Retailcrm\Retailcrm\Model\Logger\Logger $logger,
array $data = []
) {
parent::__construct($context, $data);
$this->shippingConfig = $shippingConfig;
$this->logger = $logger;
}
/**
* @param string $value
* @return Magently\Tutorial\Block\Adminhtml\Form\Field\Activation
*/
public function setInputName($value)
{
return $this->setName($value);
}
/**
* Parse to html.
*
* @return mixed
*/
public function _toHtml()
{
if (!$this->getOptions()) {
$deliveryMethods = array();
try {
$deliveryMethods = $this->shippingConfig->getActiveCarriers();
} catch (\Exception $exception) {
$this->logger->writeRow($exception->getMessage());
}
$this->addOption( 'null', "not selected");
if ($deliveryMethods) {
foreach ($deliveryMethods as $code => $delivery) {
$this->addOption($delivery->getCarrierCode(), $delivery->getConfigData('title'));
}
}
}
return parent::_toHtml();
}
}

View file

@ -0,0 +1,74 @@
<?php
namespace Retailcrm\Retailcrm\Model\Config\Backend;
class ShippingCrm extends \Magento\Framework\View\Element\Html\Select
{
/**
* @var \Retailcrm\Retailcrm\Helper\Proxy
*/
private $client;
/**
* @var \Retailcrm\Retailcrm\Model\Logger\Logger
*/
private $logger;
/**
* Activation constructor.
*
* @param \Magento\Framework\View\Element\Context $context
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Context $context,
\Retailcrm\Retailcrm\Helper\Proxy $client,
\Retailcrm\Retailcrm\Model\Logger\Logger $logger,
array $data = []
) {
parent::__construct($context, $data);
$this->client = $client;
$this->logger = $logger;
}
/**
* @param string $value
* @return Magently\Tutorial\Block\Adminhtml\Form\Field\Activation
*/
public function setInputName($value)
{
return $this->setName($value);
}
/**
* Parse to html.
*
* @return mixed
*/
public function _toHtml()
{
if (!$this->getOptions()) {
$deliveryTypes = array();
try {
$response = $this->client->deliveryTypesList();
} catch (\Exception $exception) {
$this->logger->writeRow($exception->getMessage());
}
if (isset($response) && $response->isSuccessful()) {
$deliveryTypes = $response['deliveryTypes'];
}
$this->addOption( 'null', "not selected");
if ($deliveryTypes) {
foreach ($deliveryTypes as $deliveryType) {
$this->addOption($deliveryType['code'], $deliveryType['name']);
}
}
}
return parent::_toHtml();
}
}

View file

@ -0,0 +1,71 @@
<?php
namespace Retailcrm\Retailcrm\Model\Config\Backend;
class StatusCms extends \Magento\Framework\View\Element\Html\Select
{
/**
* @var \Magento\Sales\Model\ResourceModel\Order\Status\Collection
*/
private $statusCollection;
/**
* @var \Retailcrm\Retailcrm\Model\Logger\Logger
*/
private $logger;
/**
* StatusCms constructor.
*
* @param \Magento\Framework\View\Element\Context $context
* @param \Magento\Sales\Model\ResourceModel\Order\Status\Collection $statusCollection
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Context $context,
\Magento\Sales\Model\ResourceModel\Order\Status\Collection $statusCollection,
\Retailcrm\Retailcrm\Model\Logger\Logger $logger,
array $data = []
) {
parent::__construct($context, $data);
$this->statusCollection = $statusCollection;
$this->logger = $logger;
}
/**
* @param string $value
* @return Magently\Tutorial\Block\Adminhtml\Form\Field\Activation
*/
public function setInputName($value)
{
return $this->setName($value);
}
/**
* Parse to html.
*
* @return mixed
*/
public function _toHtml()
{
if (!$this->getOptions()) {
$statuses = array();
try {
$statuses = $this->statusCollection->toOptionArray();
} catch (\Exception $exception) {
$this->logger->writeRow($exception->getMessage());
}
$this->addOption( 'null', "not selected");
if ($statuses) {
foreach ($statuses as $code => $status) {
$this->addOption( $status['value'], $status['label']);
}
}
}
return parent::_toHtml();
}
}

View file

@ -0,0 +1,75 @@
<?php
namespace Retailcrm\Retailcrm\Model\Config\Backend;
class StatusCrm extends \Magento\Framework\View\Element\Html\Select
{
/**
* @var \Retailcrm\Retailcrm\Helper\Proxy
*/
private $client;
/**
* @var \Retailcrm\Retailcrm\Model\Logger\Logger
*/
private $logger;
/**
* Activation constructor.
*
* @param \Magento\Framework\View\Element\Context $context
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Context $context,
\Retailcrm\Retailcrm\Helper\Proxy $client,
\Retailcrm\Retailcrm\Model\Logger\Logger $logger,
array $data = []
) {
parent::__construct($context, $data);
$this->client = $client;
$this->logger = $logger;
}
/**
* @param string $value
* @return Magently\Tutorial\Block\Adminhtml\Form\Field\Activation
*/
public function setInputName($value)
{
return $this->setName($value);
}
/**
* Parse to html.
*
* @return mixed
*/
public function _toHtml()
{
if (!$this->getOptions()) {
$statuses = array();
try {
$response = $this->client->statusesList();
} catch (\Exception $exception) {
$this->logger->writeRow($exception->getMessage());
}
if (isset($response) && $response->isSuccessful()) {
$statuses = $response['statuses'];
}
$this->addOption( 'null', "not selected");
if ($statuses) {
foreach ($statuses as $status) {
$this->addOption($status['code'], $status['name']);
}
}
}
return parent::_toHtml();
}
}

View file

@ -161,11 +161,11 @@ class Exchange
{
$this->logger->writeDump($order, 'doCreate');
$payments = $this->config->getValue('retailcrm/retailcrm_payment');
$shippings = $this->config->getValue('retailcrm/retailcrm_shipping');
$payments = $this->helper->getConfigPayments();
$shippings = $this->helper->getCongigShipping();
$sites = $this->helper->getMappingSites();
if ($sites) {
if ($sites && in_array($order['site'], $sites)) {
$store = $this->storeManager->getStore($sites[$order['site']]);
$websiteId = $store->getWebsiteId();
} else {
@ -178,7 +178,7 @@ class Exchange
$customer->setWebsiteId($websiteId);
if (isset($order['customer']['externalId'])) {
$customer->load($order['customer']['externalId']);
$customer = $this->customerRepository->getById($order['customer']['externalId']);
}
if (!$customer->getId()) {
@ -190,7 +190,7 @@ class Exchange
->setEmail($order['email'])
->setPassword($order['email']);
try {
$customer->save();
$this->customerRepository->save($customer);
} catch (\Exception $exception) {
$this->logger->writeRow($exception->getMessage());
}
@ -216,9 +216,32 @@ class Exchange
$quote->setCurrency();
$quote->assignCustomer($customer); //Assign quote to customer
//add items in quote
$manager = \Magento\Framework\App\ObjectManager::getInstance();
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
$productRepository = $manager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
$ditems = [];
foreach ($order['items'] as $item) {
$product = $this->product->load($item['offer']['externalId']);
if (!isset($ditems[$item['offer']['externalId']]['quantity'])) {
$ditems[$item['offer']['externalId']] = [
'quantity' => null,
'discountTotal' => null,
'initialPrice' => null,
'price_sum' => null,
'price_item' => null
];
}
$ditems[$item['offer']['externalId']]['quantity'] += $item['quantity'];
$ditems[$item['offer']['externalId']]['discountTotal'] += $item['quantity'] * $item['discountTotal'];
$ditems[$item['offer']['externalId']]['initialPrice'] = (float)$item['initialPrice'];
$ditems[$item['offer']['externalId']]['price_sum'] = $ditems[$item['offer']['externalId']]['initialPrice'] * $ditems[$item['offer']['externalId']]['quantity'] - $ditems[$item['offer']['externalId']]['discountTotal'];
$ditems[$item['offer']['externalId']]['price_item'] = $ditems[$item['offer']['externalId']]['price_sum'] / $ditems[$item['offer']['externalId']]['quantity'];
}
//add items in quote
foreach ($ditems as $id =>$item) {
$product = $productRepository->getById($id,false, $store->getId(), false);
$product->setPrice($item['initialPrice']);
$quote->addProduct(
$product,
@ -228,8 +251,8 @@ class Exchange
$products = [];
foreach ($order['items'] as $item) {
$products[$item['offer']['externalId']] = ['qty' => $item['quantity']];
foreach ($ditems as $id => $item) {
$products[$id] = ['product_id'=>$id,'qty' => $item['quantity']];
}
$orderData = [
@ -280,17 +303,19 @@ class Exchange
$quote->setPaymentMethod($payments[$paymentType]);
$quote->setInventoryProcessed(false);
$quote->save();
/** @var \Magento\Quote\Api\CartRepositoryInterface $quoteRepository */
$quoteRepository = $manager->create(\Magento\Quote\Api\CartRepositoryInterface::class);
$quoteRepository->save($quote);
// Set Sales Order Payment
$quote->getPayment()->importData(['method' => $payments[$paymentType]]);
// Collect Totals & Save Quote
$quote->collectTotals()->save();
$quote->collectTotals();
$quoteRepository->save($quote);
// Create Order From Quote
$magentoOrder = $this->quoteManagement->submit($quote);
$increment_id = $magentoOrder->getId();
$this->api->ordersFixExternalIds(
@ -312,8 +337,8 @@ class Exchange
*/
private function doCreateUp($order)
{
$manager = \Magento\Framework\App\ObjectManager::getInstance();
$this->logger->writeDump($order, 'doCreateUp');
$response = $this->api->ordersGet($order['id'], $by = 'id');
if (!$response->isSuccessful()) {
@ -324,13 +349,13 @@ class Exchange
$order = $response['order'];
}
$payments = $this->config->getValue('retailcrm/retailcrm_payment');
$shippings = $this->config->getValue('retailcrm/retailcrm_shipping');
$payments = $this->helper->getConfigPayments();
$shippings = $this->helper->getCongigShipping();
$region = $this->regionFactory->create();
$sites = $this->helper->getMappingSites();
if ($sites) {
if ($sites && in_array($order['site'], $sites)) {
$store = $this->storeManager->getStore($sites[$order['site']]);
$websiteId = $store->getWebsiteId();
} else {
@ -342,7 +367,7 @@ class Exchange
$customer->setWebsiteId($websiteId);
if (isset($order['customer']['externalId'])) {
$customer->load($order['customer']['externalId']); // load customer by external id
$customer = $this->customerRepository->getById($order['customer']['externalId']);
}
//Create object of quote
@ -361,9 +386,31 @@ class Exchange
$quote->setCustomerIsGuest(1);
}
//add items in quote
$ditems = [];
foreach ($order['items'] as $item) {
$product = $this->product->load($item['offer']['externalId']);
if (!isset($ditems[$item['offer']['externalId']]['quantity'])) {
$ditems[$item['offer']['externalId']] = [
'quantity' => null,
'discountTotal' => null,
'initialPrice' => null,
'price_sum' => null,
'price_item' => null
];
}
$ditems[$item['offer']['externalId']]['quantity'] += $item['quantity'];
$ditems[$item['offer']['externalId']]['discountTotal'] += $item['quantity'] * $item['discountTotal'];
$ditems[$item['offer']['externalId']]['initialPrice'] = (float)$item['initialPrice'];
$ditems[$item['offer']['externalId']]['price_sum'] = $ditems[$item['offer']['externalId']]['initialPrice'] * $ditems[$item['offer']['externalId']]['quantity'] - $ditems[$item['offer']['externalId']]['discountTotal'];
$ditems[$item['offer']['externalId']]['price_item'] = $ditems[$item['offer']['externalId']]['price_sum'] / $ditems[$item['offer']['externalId']]['quantity'];
}
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
$productRepository = $manager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
//add items in quote
foreach ($ditems as $id => $item) {
$product = $productRepository->getById($id,false, $store->getId(), false);
$product->setPrice($item['initialPrice']);
$quote->addProduct(
$product,
@ -373,8 +420,8 @@ class Exchange
$products = [];
foreach ($order['items'] as $item) {
$products[$item['offer']['externalId']] = ['qty' => $item['quantity']];
foreach ($ditems as $id => $item) {
$products[$id] = ['product_id'=>$id,'qty' => $item['quantity']];
}
$orderData = [
@ -435,16 +482,20 @@ class Exchange
];
$quote->setReservedOrderId($orderDataUp['increment_id']);
$quote->save();
/** @var \Magento\Quote\Api\CartRepositoryInterface $quoteRepository */
$quoteRepository = $manager->create(\Magento\Quote\Api\CartRepositoryInterface::class);
$quoteRepository->save($quote);
// Set Sales Order Payment
$quote->getPayment()->importData(['method' => $payments[$paymentType]]);
// Collect Totals & Save Quote
$quote->collectTotals()->save();
$quote->collectTotals();
$quoteRepository->save($quote);
// Create Order From Quote
$magentoOrder = $this->quoteManagement->submit($quote, $orderDataUp);
$oldOrder->setStatus('canceled')->save();
$increment_id = $magentoOrder->getId();
@ -469,7 +520,7 @@ class Exchange
{
$this->logger->writeDump($order, 'doUpdate');
$Status = $this->config->getValue('retailcrm/retailcrm_status');
$Status = $this->helper->getCongigStatus();
$Status = array_flip(array_filter($Status));
$magentoOrder = $this->order->load($order['externalId']);
@ -508,11 +559,11 @@ class Exchange
foreach ($orderHistory as $change) {
$orderId = $change['order']['id'];
$change['order'] = self::removeEmpty($change['order']);
if (isset($change['order']['items'])) {
$items = [];
foreach ($change['order']['items'] as $item) {
if (isset($change['created'])) {
$item['create'] = 1;
@ -551,7 +602,7 @@ class Exchange
if (isset($change['item'])) {
if (isset($orders[$change['order']['id']]['items'])
&& $orders[$change['order']['id']]['items'][$change['item']['id']]
&& isset($orders[$change['order']['id']]['items'][$change['item']['id']])
) {
$orders[$change['order']['id']]['items'][$change['item']['id']] = array_merge(
$orders[$change['order']['id']]['items'][$change['item']['id']],
@ -576,34 +627,6 @@ class Exchange
$orders[$change['order']['id']]['order_edit'] = 1;
}
} else {
if (isset($fields['delivery'][$change['field']])
&& $fields['delivery'][$change['field']] == 'service'
) {
$orders[$orderId]['delivery']['service']['code'] = self::newValue($change['newValue']);
} elseif (isset($fields['delivery'][$change['field']])) {
$field = $fields['delivery'][$change['field']];
$orders[$orderId]['delivery'][$field] = self::newValue($change['newValue']);
unset($field);
} elseif (isset($fields['orderAddress'][$change['field']])) {
$field = $fields['orderAddress'][$change['field']];
$orders[$orderId]['delivery']['address'][$field] = self::newValue($change['newValue']);
unset($field);
} elseif (isset($fields['integrationDelivery'][$change['field']])) {
$field = $fields['integrationDelivery'][$change['field']];
$orders[$orderId]['delivery']['service'][$field] = self::newValue($change['newValue']);
unset($field);
} elseif (isset($fields['customerContragent'][$change['field']])) {
$field = $fields['customerContragent'][$change['field']];
$orders[$orderId][$field] = self::newValue($change['newValue']);
unset($field);
} elseif (strripos($change['field'], 'custom_') !== false) {
$field = str_replace('custom_', '', $change['field']);
$orders[$orderId]['customFields'][$field] = self::newValue($change['newValue']);
unset($field);
} elseif (isset($fields['order'][$change['field']])) {
$orders[$orderId][$fields['order'][$change['field']]] = self::newValue($change['newValue']);
}
if (isset($change['created'])) {
$orders[$orderId]['create'] = 1;
}

View file

@ -19,6 +19,7 @@ class Icml
private $resourceModelProduct;
private $searchCriteriaBuilder;
private $productRepository;
private $dimensionFields = ['height', 'length', 'width'];
public function __construct(
\Magento\Store\Model\StoreManagerInterface $manager,
@ -105,7 +106,13 @@ class Icml
$e = $this->eCategories->appendChild(
$this->dd->createElement('category')
);
$e->appendChild($this->dd->createTextNode($category->getName()));
$e->appendChild($this->dd->createElement('name', \htmlspecialchars($category->getName())));
if ($category->getImageUrl()) {
$e->appendChild($this->dd->createElement('picture', \htmlspecialchars($category->getImageUrl())));
}
$e->setAttribute('id', $category->getId());
if ($category->getParentId() > 1) {
@ -211,6 +218,20 @@ class Icml
);
}
if (!empty($offer['dimensions'])) {
$e->appendChild($this->dd->createElement('dimensions'))
->appendChild(
$this->dd->createTextNode($offer['dimensions'])
);
}
if (!empty($offer['weight'])) {
$e->appendChild($this->dd->createElement('weight'))
->appendChild(
$this->dd->createTextNode($offer['weight'])
);
}
if (!empty($offer['params'])) {
foreach ($offer['params'] as $param) {
$paramNode = $this->dd->createElement('param');
@ -303,8 +324,16 @@ class Icml
$offer['vendor'] = $associatedProduct === null
? $product->getAttributeText('manufacturer')
: $associatedProduct->getAttributeText('manufacturer');
$offer['weight'] = $associatedProduct === null
? $product->getWeight()
: $associatedProduct->getWeight();
$offer['params'] = $this->getOfferParams($product, $customAdditionalAttributes, $associatedProduct);
$params = $this->getOfferParams($product, $customAdditionalAttributes, $associatedProduct);
$offer['params'] = $params['params'];
$offer['dimensions'] = $params['dimensions'];
unset($params);
return $offer;
}
@ -327,8 +356,16 @@ class Icml
}
$attributes = explode(',', $customAdditionalAttributes);
$dimensionsAttrs = [];
$dimensions = '';
foreach ($attributes as $attributeCode) {
if ($this->checkDimension($attributeCode) !== false) {
$dimensionsAttrs += $this->checkDimension($attributeCode);
continue;
}
$attribute = $this->resourceModelProduct->getAttribute($attributeCode);
$attributeValue = $associatedProduct
? $associatedProduct->getData($attributeCode)
@ -344,7 +381,28 @@ class Icml
}
}
return $params;
if ($dimensionsAttrs && count($dimensionsAttrs) == 3) {
$length = $associatedProduct
? $associatedProduct->getData($dimensionsAttrs['length'])
: $product->getData($dimensionsAttrs['length']);
$width = $associatedProduct
? $associatedProduct->getData($dimensionsAttrs['width'])
: $product->getData($dimensionsAttrs['width']);
$height = $associatedProduct
? $associatedProduct->getData($dimensionsAttrs['height'])
: $product->getData($dimensionsAttrs['height']);
if ($length && $width && $height) {
$dimensions = sprintf(
'%s/%s/%s',
$length,
$width,
$height
);
}
}
return ['params' => $params, 'dimensions' => $dimensions];
}
/**
@ -377,4 +435,20 @@ class Icml
return $quantity;
}
/**
* @param string $attrCode
*
* @return mixed
*/
private function checkDimension($attrCode)
{
foreach ($this->dimensionFields as $dimensionField) {
if (mb_strpos($attrCode, $dimensionField) !== false) {
return [$dimensionField => $attrCode];
}
}
return false;
}
}

View file

@ -36,6 +36,7 @@ class Customer implements \Magento\Framework\Event\ObserverInterface
$customer = $observer->getEvent()->getCustomer();
$this->customer = $this->serviceCustomer->process($customer);
$this->api->setSite($this->helper->getSite($customer->getStore()));
$response = $this->api->customersEdit($this->customer);
if ($response === false) {
@ -43,7 +44,6 @@ class Customer implements \Magento\Framework\Event\ObserverInterface
}
if (!$response->isSuccessful() && $response->errorMsg == $this->api->getErrorText('errorNotFound')) {
$this->api->setSite($this->helper->getSite($customer->getStore()));
$this->api->customersCreate($this->customer);
}

View file

@ -15,6 +15,7 @@ class OrderCreate implements \Magento\Framework\Event\ObserverInterface
private $registry;
private $order;
private $serviceOrder;
private $serviceCustomer;
/**
* Constructor
@ -22,6 +23,7 @@ class OrderCreate implements \Magento\Framework\Event\ObserverInterface
* @param \Magento\Framework\Registry $registry
* @param \Retailcrm\Retailcrm\Model\Logger\Logger $logger
* @param \Retailcrm\Retailcrm\Model\Service\Order $serviceOrder
* @param \Retailcrm\Retailcrm\Model\Service\Customer $serviceCustomer
* @param Helper $helper
* @param ApiClient $api
*/
@ -29,12 +31,14 @@ class OrderCreate implements \Magento\Framework\Event\ObserverInterface
\Magento\Framework\Registry $registry,
\Retailcrm\Retailcrm\Model\Logger\Logger $logger,
\Retailcrm\Retailcrm\Model\Service\Order $serviceOrder,
\Retailcrm\Retailcrm\Model\Service\Customer $serviceCustomer,
Helper $helper,
ApiClient $api
) {
$this->logger = $logger;
$this->registry = $registry;
$this->serviceOrder = $serviceOrder;
$this->serviceCustomer = $serviceCustomer;
$this->helper = $helper;
$this->api = $api;
$this->order = [];
@ -55,6 +59,7 @@ class OrderCreate implements \Magento\Framework\Event\ObserverInterface
return false;
}
/** @var \Magento\Sales\Model\Order $order */
$order = $observer->getEvent()->getOrder();
$this->api->setSite($this->helper->getSite($order->getStore()));
@ -62,13 +67,8 @@ class OrderCreate implements \Magento\Framework\Event\ObserverInterface
return false;
}
$billingAddress = $order->getBillingAddress();
$this->order = $this->serviceOrder->process($order);
$this->setCustomer(
$order,
$billingAddress
);
$this->setCustomer($order);
Helper::filterRecursive($this->order);
@ -80,16 +80,22 @@ class OrderCreate implements \Magento\Framework\Event\ObserverInterface
}
/**
* @param $order
* @param $billingAddress
* @param \Magento\Sales\Model\Order $order
* @param \Magento\Sales\Model\Order\Address $billingAddress
*/
private function setCustomer($order, $billingAddress)
private function setCustomer($order)
{
if ($order->getCustomerIsGuest() == 1) {
$customer = $this->getCustomerByEmail($order->getCustomerEmail());
if ($customer !== false) {
$this->order['customer']['id'] = $customer['id'];
} else {
$newCustomer = $this->serviceCustomer->prepareCustomerFromOrder($order);
$response = $this->api->customersCreate($newCustomer);
if ($response && isset($response['id'])) {
$this->order['customer']['id'] = $response['id'];
}
}
}
@ -97,18 +103,7 @@ class OrderCreate implements \Magento\Framework\Event\ObserverInterface
if ($this->existsInCrm($order->getCustomerId(), 'customersGet')) {
$this->order['customer']['externalId'] = $order->getCustomerId();
} else {
$preparedCustomer = [
'externalId' => $order->getCustomerId(),
'firstName' => $order->getCustomerFirstname(),
'lastName' => $order->getCustomerLastname(),
'email' => $order->getCustomerEmail()
];
if ($billingAddress->getTelephone()) {
$preparedCustomer['phones'][] = [
'number' => $billingAddress->getTelephone()
];
}
$preparedCustomer = $this->serviceCustomer->process($order->getCustomer());
if ($this->api->customersCreate($preparedCustomer)) {
$this->order['customer']['externalId'] = $order->getCustomerId();

View file

@ -53,9 +53,11 @@ class OrderUpdate implements \Magento\Framework\Event\ObserverInterface
$order = $observer->getEvent()->getOrder();
if ($order) {
$statusList = $this->helper->getCongigStatus();
$this->order = [
'externalId' => $order->getId(),
'status' => $this->config->getValue('retailcrm/retailcrm_status/' . $order->getStatus())
'status' => $statusList[$order->getStatus()]
];
if ($order->getBaseTotalDue() == 0) {

View file

@ -25,7 +25,6 @@ class Customer implements CustomerManagerInterface
* @param \Magento\Customer\Model\Customer $customer
*
* @return array $preparedCustomer
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function process(\Magento\Customer\Model\Customer $customer)
{
@ -60,6 +59,52 @@ class Customer implements CustomerManagerInterface
return $preparedCustomer;
}
/**
* @param \Magento\Sales\Model\Order $order
*
* @return array
*/
public function prepareCustomerFromOrder(\Magento\Sales\Model\Order $order)
{
$billing = $order->getBillingAddress();
$preparedCustomer = [
'email' => $billing->getEmail(),
'firstName' => $billing->getFirstname(),
'patronymic' => $billing->getMiddlename(),
'lastName' => $billing->getLastname(),
'createdAt' => $order->getCreatedAt(),
'address' => [
'countryIso' => $billing->getCountryId(),
'index' => $billing->getPostcode(),
'region' => $billing->getRegion(),
'city' => $billing->getCity(),
'street' => is_array($billing->getStreet())
? implode(', ', $billing->getStreet())
: $billing->getStreet(),
'text' => sprintf(
'%s %s %s %s',
$billing->getPostcode(),
$billing->getRegion(),
$billing->getCity(),
is_array($billing->getStreet())
? implode(', ', $billing->getStreet())
: $billing->getStreet()
)
]
];
if ($billing->getTelephone()) {
$preparedCustomer['phones'] = [
[
'number' => $billing->getTelephone()
]
];
}
return $preparedCustomer;
}
private function getAddress(\Magento\Customer\Model\Customer $customer)
{
$billingAddress = $customer->getDefaultBillingAddress();

View file

@ -3,6 +3,7 @@
namespace Retailcrm\Retailcrm\Model\Service;
use Retailcrm\Retailcrm\Helper\Data as Helper;
use Magento\Framework\App\Config\ScopeConfigInterface;
class IntegrationModule
{
@ -110,9 +111,15 @@ class IntegrationModule
}
if ($response->isSuccessful() && $active == true) {
$scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT;
$scopeId = 0;
$this->resourceConfig->saveConfig(
Helper::XML_PATH_RETAILCRM . 'general/client_id_in_crm',
$this->clientId
$this->clientId,
$scope,
$scopeId
);
return true;

View file

@ -0,0 +1,55 @@
<?php
namespace Retailcrm\Retailcrm\Model\Service;
use Magento\Catalog\Api\ProductRepositoryInterface;
class InventoriesUpload
{
private $productRepo;
private $api;
public function __construct(
ProductRepositoryInterface $productRepo,
\Retailcrm\Retailcrm\Helper\Proxy $api
) {
$this->productRepo = $productRepo;
$this->api = $api;
}
/**
* {@inheritdoc}
*/
public function uploadInventory()
{
if (!$this->api->isConfigured()) {
return false;
}
$page = 1;
do {
$response = $this->api->storeInventories(array(), $page, 250);
if ($response === false || !$response->isSuccessful()) {
return false;
}
foreach ($response['offers'] as $offer) {
if (isset($offer['externalId'])) {
$product = $this->productRepo->getById($offer['externalId']);
$product->setStockData(
['qty' => $offer['quantity'],
'is_in_stock' => $offer['quantity'] > 0]
);
$product->save();
}
}
$totalPageCount = $response['pagination']['totalPageCount'];
$page++;
} while ($page <= $totalPageCount);
return true;
}
}

View file

@ -34,23 +34,26 @@ class Order implements \Retailcrm\Retailcrm\Api\OrderManagerInterface
{
$items = $order->getAllItems();
$products = $this->addProducts($items);
$billingAddress = $order->getBillingAddress();
$shippingAddress = $order->getShippingAddress();
$shipping = $this->getShippingCode($order->getShippingMethod());
$shipList = $this->helper->getCongigShipping();
$statusList = $this->helper->getCongigStatus();
$paymentList = $this->helper->getConfigPayments();
$preparedOrder = [
'externalId' => $order->getId(),
'number' => $order->getRealOrderId(),
'createdAt' => $order->getCreatedAt(),
'lastName' => $order->getCustomerLastname(),
'firstName' => $order->getCustomerFirstname(),
'patronymic' => $order->getCustomerMiddlename(),
'email' => $order->getCustomerEmail(),
'phone' => $billingAddress->getTelephone(),
'status' => $this->config->getValue('retailcrm/retailcrm_status/' . $order->getStatus()),
'lastName' => $shippingAddress->getLastname(),
'firstName' => $shippingAddress->getFirstname(),
'patronymic' => $shippingAddress->getMiddlename(),
'email' => $shippingAddress->getEmail(),
'phone' => $shippingAddress->getTelephone(),
'status' => $statusList[$order->getStatus()],
'items' => $products,
'delivery' => [
'code' => $this->config->getValue('retailcrm/retailcrm_shipping/' . $shipping),
'code' => $shipList[$shipping],
'cost' => $order->getShippingAmount(),
'address' => [
'index' => $shippingAddress->getData('postcode'),
@ -73,22 +76,20 @@ class Order implements \Retailcrm\Retailcrm\Api\OrderManagerInterface
]
];
if ($billingAddress->getData('country_id')) {
$preparedOrder['countryIso'] = $billingAddress->getData('country_id');
$codeShop = $this->config->getValue('retailcrm/retailcrm_site/default');
if ($shippingAddress->getData('country_id')) {
$preparedOrder['countryIso'] = $shippingAddress->getData('country_id');
}
if ($this->helper->getGeneralSettings('api_version') == 'v4') {
$preparedOrder['discount'] = abs($order->getDiscountAmount());
$preparedOrder['paymentType'] = $this->config->getValue(
'retailcrm/retailcrm_payment/' . $order->getPayment()->getMethodInstance()->getCode()
);
$preparedOrder['paymentType'] = $paymentList[$order->getPayment()->getMethodInstance()->getCode()];
} elseif ($this->helper->getGeneralSettings('api_version') == 'v5') {
$preparedOrder['discountManualAmount'] = abs($order->getDiscountAmount());
$payment = [
'type' => $this->config->getValue(
'retailcrm/retailcrm_payment/' . $order->getPayment()->getMethodInstance()->getCode()
),
'externalId' => $order->getId(),
'type'=> $paymentList[$order->getPayment()->getMethodInstance()->getCode()],
'externalId' => $codeShop.$order->getId(),
'order' => [
'externalId' => $order->getId(),
]

View file

@ -24,6 +24,7 @@ class Attribute implements \Magento\Framework\Option\ArrayInterface
'select',
'price'
];
$attributes = $this->entityType->loadByCode('catalog_product')->getAttributeCollection();
$attributes->addFieldToFilter('frontend_input', $types);

View file

@ -0,0 +1,14 @@
<?php
namespace Retailcrm\Retailcrm\Model\Setting;
class Select implements \Magento\Framework\Option\ArrayInterface
{
public function toOptionArray()
{
return [
['value' => true, 'label' => __('Yes')],
['value' => false, 'label' => __('No')]
];
}
}

View file

@ -1 +1 @@
Magento 2 module for interaction with retailCRM
Magento 2 module for interaction with RetailCRM

View file

@ -2,7 +2,9 @@
namespace Retailcrm\Retailcrm\Test\Helpers;
class FieldsetTest extends \PHPUnit\Framework\TestCase
use Retailcrm\Retailcrm\Test\TestCase;
class FieldsetTest extends TestCase
{
protected $elementMock;
protected $authSessionMock;
@ -18,6 +20,7 @@ class FieldsetTest extends \PHPUnit\Framework\TestCase
protected $testElementId = 'test_element_id';
protected $testFieldSetCss = 'test_fieldset_css';
protected $objectFactory;
protected $secureRenderer;
public function setUp()
{
@ -86,6 +89,23 @@ class FieldsetTest extends \PHPUnit\Framework\TestCase
$factoryCollection->expects($this->any())->method('create')->willReturn($elementCollection);
$rendererMock = $this->createMock(\Magento\Framework\Data\Form\Element\Renderer\RendererInterface::class);
if (class_exists(\Magento\Framework\View\Helper\SecureHtmlRenderer::class)) {
$this->secureRenderer = $this->createMock(\Magento\Framework\View\Helper\SecureHtmlRenderer::class);
$this->secureRenderer->method('renderEventListenerAsTag')
->willReturnCallback(
function (string $event, string $js, string $selector): string {
return "<script>document.querySelector('$selector').$event = function () { $js };</script>";
}
);
$this->secureRenderer->method('renderStyleAsTag')
->willReturnCallback(
function (string $style, string $selector): string {
return "<style>$selector { $style }</style>";
}
);
}
$this->urlModelMock = $this->createMock(\Magento\Backend\Model\Url::class);
$this->layoutMock = $this->createMock(\Magento\Framework\View\Layout::class);
$this->groupMock = $this->createMock(\Magento\Config\Model\Config\Structure\Element\Group::class);
@ -98,9 +118,10 @@ class FieldsetTest extends \PHPUnit\Framework\TestCase
$this->helperMock = $this->createMock(\Magento\Framework\View\Helper\Js::class);
$this->form = $this->createPartialMock(
\Magento\Config\Block\System\Config\Form::class,
['getElements', 'getRequest']
//['getElements', 'getRequest']
['getRequest']
);
$this->form->expects($this->any())->method('getElements')->willReturn($elementCollection);
//$this->form->expects($this->any())->method('getElements')->willReturn($elementCollection);
$this->form->expects($this->any())->method('getRequest')->willReturn($this->requestMock);
}
}

58
src/Test/TestCase.php Normal file
View file

@ -0,0 +1,58 @@
<?php
namespace Retailcrm\Retailcrm\Test;
// backward compatibility with phpunit < v.6
if (!class_exists('\PHPUnit\Framework\TestCase')) {
class_alias('\PHPUnit_Framework_TestCase', '\PHPUnit\Framework\TestCase');
abstract class TestCase extends \PHPUnit\Framework\TestCase
{
public function createMock($originalClassName)
{
if (method_exists(\PHPUnit\Framework\TestCase::class, 'createMock')) {
return parent::createMock($originalClassName);
} else {
return $this->getMockBuilder($originalClassName)
->disableOriginalConstructor()
->disableOriginalClone()
->disableArgumentCloning()
->getMock();
}
}
protected function createPartialMock($originalClassName, $methods)
{
if (method_exists(\PHPUnit\Framework\TestCase::class, 'createPartialMock')) {
return parent::createMock($originalClassName);
} else {
return $this->getMockBuilder($originalClassName)
->disableOriginalConstructor()
->disableOriginalClone()
->disableArgumentCloning()
// ->disallowMockingUnknownTypes()
->setMethods(empty($methods) ? null : $methods)
->getMock();
}
}
}
} else {
abstract class TestCase extends \PHPUnit\Framework\TestCase
{
public function createMock($originalClassName)
{
if (method_exists(\PHPUnit\Framework\TestCase::class, 'createMock')) {
return parent::createMock($originalClassName);
} else {
return $this->getMockBuilder($originalClassName)
->disableOriginalConstructor()
->disableOriginalClone()
->disableArgumentCloning()
->getMock();
}
}
}
}

View file

@ -52,7 +52,8 @@ class PaymentTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest
'client' => $client,
'paymentConfig' => $paymentConfig,
'context' => $this->context,
'objectFactory' => $this->objectFactory
'objectFactory' => $this->objectFactory,
'secureRenderer' => $this->secureRenderer
];
$payment = $this->objectManager->getObject(

View file

@ -52,7 +52,8 @@ class ShippingTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest
'client' => $client,
'shippingConfig' => $shippingConfig,
'context' => $this->context,
'objectFactory' => $this->objectFactory
'objectFactory' => $this->objectFactory,
'secureRenderer' => $this->secureRenderer
];
$shipping = $this->objectManager->getObject(

View file

@ -43,7 +43,8 @@ class SiteTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest
'data' => ['group' => $this->groupMock],
'client' => $client,
'context' => $this->context,
'objectFactory' => $this->objectFactory
'objectFactory' => $this->objectFactory,
'secureRenderer' => $this->secureRenderer
];
$site = $this->objectManager->getObject(

View file

@ -55,7 +55,8 @@ class SitesTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest
'client' => $client,
'storeManager' => $storeManager,
'context' => $this->context,
'objectFactory' => $this->objectFactory
'objectFactory' => $this->objectFactory,
'secureRenderer' => $this->secureRenderer
];
$sites = $this->objectManager->getObject(

View file

@ -52,7 +52,8 @@ class StatusTest extends \Retailcrm\Retailcrm\Test\Helpers\FieldsetTest
'client' => $client,
'statusCollection' => $statusCollection,
'context' => $this->context,
'objectFactory' => $this->objectFactory
'objectFactory' => $this->objectFactory,
'secureRenderer' => $this->secureRenderer
];
$status = $this->objectManager->getObject(

View file

@ -0,0 +1,81 @@
<?php
namespace Retailcrm\Retailcrm\Test\Unit\Block\Frontend;
use Retailcrm\Retailcrm\Test\TestCase;
class DaemonCollectorTest extends TestCase
{
private $unit;
private $customer;
const SITE_KEY = 'RC-XXXXXXX-X';
public function setUp()
{
$context = $this->createMock(\Magento\Framework\View\Element\Template\Context::class);
$customerSession = $this->createMock(\Magento\Customer\Model\Session::class);
$storeManager = $this->createMock(\Magento\Store\Model\StoreManager::class);
$storeResolver = $this->createMock(\Magento\Store\Model\StoreResolver::class);
$helper = $this->createMock(\Retailcrm\Retailcrm\Helper\Data::class);
$this->customer = $this->createMock(\Magento\Customer\Model\Customer::class);
$store = $this->createMock(\Magento\Store\Model\Store::class);
$customerSession->expects($this->any())
->method('getCustomer')
->willReturn($this->customer);
$storeResolver->expects($this->any())
->method('getCurrentStoreId')
->willReturn(1);
$store->expects($this->any())
->method('getWebsiteId')
->willReturn(1);
$storeManager->expects($this->any())
->method('getStore')
->willReturn($store);
$helper->expects($this->any())
->method('getSiteKey')
->willReturn(self::SITE_KEY);
$context->expects($this->any())
->method('getStoreManager')
->willReturn($storeManager);
$this->unit = new \Retailcrm\Retailcrm\Block\Frontend\DaemonCollector(
$context,
$customerSession,
$storeResolver,
$helper
);
}
public function testGetJSWithCustomer()
{
$this->customer->expects($this->any())
->method('getId')
->willReturn(1);
$js = $this->unit->buildScript()->getJs();
$this->assertContains('<script type="text/javascript">', $js);
$this->assertContains('</script>', $js);
$this->assertContains('_rc(\'send\', \'pageView\');', $js);
$this->assertContains(self::SITE_KEY, $js);
$this->assertContains('customerId', $js);
}
public function testGetJSWithoutCustomer()
{
$this->customer->expects($this->any())
->method('getId')
->willReturn(null);
$js = $this->unit->buildScript()->getJs();
$this->assertContains('<script type="text/javascript">', $js);
$this->assertContains('</script>', $js);
$this->assertContains('_rc(\'send\', \'pageView\');', $js);
$this->assertContains(self::SITE_KEY, $js);
$this->assertNotContains('customerId', $js);
}
}

View file

@ -2,7 +2,9 @@
namespace Retailcrm\Retailcrm\Test\Unit\Model\Observer;
class CustomerTest extends \PHPUnit\Framework\TestCase
use Retailcrm\Retailcrm\Test\TestCase;
class CustomerTest extends TestCase
{
private $mockApi;
private $mockResponse;

View file

@ -2,10 +2,12 @@
namespace Retailcrm\Retailcrm\Test\Unit\Observer;
use Retailcrm\Retailcrm\Test\TestCase;
/**
* Order create observer test class
*/
class OrderCreateTest extends \PHPUnit\Framework\TestCase
class OrderCreateTest extends TestCase
{
private $unit;
private $mockEvent;
@ -20,6 +22,8 @@ class OrderCreateTest extends \PHPUnit\Framework\TestCase
private $mockLogger;
private $mockServiceOrder;
private $mockHelper;
private $mockServiceCustomer;
private $mockCustomer;
public function setUp()
{
@ -56,6 +60,12 @@ class OrderCreateTest extends \PHPUnit\Framework\TestCase
$this->mockOrder = $this->getMockBuilder(\Magento\Sales\Model\Order::class)
->disableOriginalConstructor()
->setMethods([
'getCustomer',
'getId',
'getBillingAddress',
'getStore'
])
->getMock();
$this->mockStore = $this->getMockBuilder(\Magento\Store\Model\Store::class)
@ -81,10 +91,62 @@ class OrderCreateTest extends \PHPUnit\Framework\TestCase
->disableOriginalConstructor()
->getMock();
$this->mockServiceCustomer = $this->getMockBuilder(\Retailcrm\Retailcrm\Model\Service\Customer::class)
->disableOriginalConstructor()
->getMock();
$this->mockServiceCustomer->expects($this->any())->method('process')->willReturn($this->getCustomerTestData());
$this->mockServiceCustomer
->expects($this->any())
->method('prepareCustomerFromOrder')
->willReturn(
$this->getCustomerTestData()
);
$this->mockCustomer = $this->getMockBuilder(\Magento\Customer\Model\Customer::class)
->disableOriginalConstructor()
->setMethods([
'getId',
'getEmail',
'getFirstname',
'getMiddlename',
'getLastname',
'getStore',
'getGender',
'getDob',
'getDefaultBillingAddress',
'getAddressesCollection'
])
->getMock();
$testData = $this->getAfterSaveCustomerTestData();
// mock Customer
$this->mockCustomer->expects($this->any())
->method('getId')
->willReturn($testData['id']);
$this->mockCustomer->expects($this->any())
->method('getEmail')
->willReturn($testData['email']);
$this->mockCustomer->expects($this->any())
->method('getFirstname')
->willReturn($testData['firstname']);
$this->mockCustomer->expects($this->any())
->method('getMiddlename')
->willReturn($testData['middlename']);
$this->mockCustomer->expects($this->any())
->method('getLastname')
->willReturn($testData['lastname']);
$this->unit = new \Retailcrm\Retailcrm\Model\Observer\OrderCreate(
$this->mockRegistry,
$this->mockLogger,
$this->mockServiceOrder,
$this->mockServiceCustomer,
$this->mockHelper,
$this->mockApi
);
@ -177,6 +239,10 @@ class OrderCreateTest extends \PHPUnit\Framework\TestCase
->method('getStore')
->willReturn($this->mockStore);
$this->mockOrder->expects($this->any())
->method('getCustomer')
->willReturn($this->mockCustomer);
// mock Event
$this->mockEvent->expects($this->any())
->method('getOrder')
@ -379,4 +445,37 @@ class OrderCreateTest extends \PHPUnit\Framework\TestCase
]
];
}
/**
* Get test customer data
*
* @return array
*/
private function getAfterSaveCustomerTestData()
{
return [
'id' => 1,
'email' => 'test@mail.com',
'firstname' => 'TestFirstname',
'lastname' => 'Testlastname',
'middlename' => 'Testmiddlename',
'birthday' => '1990-01-01',
'gender' => 1
];
}
/**
* @return array
*/
private function getCustomerTestData()
{
return [
'externalId' => 1,
'email' => 'test@mail.com',
'firstName' => 'TestFirstname',
'lastName' => 'Testlastname',
'patronymic' => 'Testmiddlename',
'createdAt' => \date('Y-m-d H:i:s')
];
}
}

View file

@ -2,7 +2,9 @@
namespace Retailcrm\Retailcrm\Test\Unit\Observer;
class OrderUpdateTest extends \PHPUnit\Framework\TestCase
use Retailcrm\Retailcrm\Test\TestCase;
class OrderUpdateTest extends TestCase
{
private $unit;
private $objectManager;

View file

@ -2,11 +2,15 @@
namespace Retailcrm\Retailcrm\Test\Unit\Model\Service;
class CustomerTest extends \PHPUnit\Framework\TestCase
use Retailcrm\Retailcrm\Test\TestCase;
class CustomerTest extends TestCase
{
private $mockData;
private $mockCustomer;
private $unit;
private $mockOrder;
private $mockBillingAddress;
public function setUp()
{
@ -29,6 +33,59 @@ class CustomerTest extends \PHPUnit\Framework\TestCase
'getAddressesCollection'
])
->getMock();
$this->mockOrder = $this->getMockBuilder(\Magento\Sales\Model\Order::class)
->disableOriginalConstructor()
->setMethods([
'getBillingAddress',
])
->getMock();
$this->mockBillingAddress = $this->getMockBuilder(\Magento\Customer\Model\Address\AddressModelInterface::class)
->disableOriginalConstructor()
->setMethods([
'getTelephone',
'getEmail',
'getData',
'getFirstname',
'getMiddlename',
'getLastname',
'getCountryId',
'getPostcode',
'getRegion',
'getCity',
'getStreet'
])
->getMockForAbstractClass();
$this->unit = new \Retailcrm\Retailcrm\Model\Service\Customer(
$this->mockData
);
}
public function testPrepareCustomerFromOrder()
{
$this->mockOrder->expects($this->any())
->method('getBillingAddress')
->willReturn($this->mockBillingAddress);
$result = $this->unit->prepareCustomerFromOrder($this->mockOrder);
$this->assertNotEmpty($result);
$this->assertInternalType('array', $result);
$this->assertArrayNotHasKey('externalId', $result);
$this->assertArrayHasKey('email', $result);
$this->assertArrayHasKey('firstName', $result);
$this->assertArrayHasKey('lastName', $result);
$this->assertArrayHasKey('patronymic', $result);
$this->assertArrayHasKey('address', $result);
$this->assertInternalType('array', $result['address']);
$this->assertArrayHasKey('countryIso', $result['address']);
$this->assertArrayHasKey('index', $result['address']);
$this->assertArrayHasKey('region', $result['address']);
$this->assertArrayHasKey('city', $result['address']);
$this->assertArrayHasKey('street', $result['address']);
$this->assertArrayHasKey('text', $result['address']);
}
/**
@ -107,10 +164,6 @@ class CustomerTest extends \PHPUnit\Framework\TestCase
->method('getAddressesCollection')
->willReturn([$mockAddress]);
$this->unit = new \Retailcrm\Retailcrm\Model\Service\Customer(
$this->mockData
);
$result = $this->unit->process($this->mockCustomer);
$this->assertNotEmpty($result);

View file

@ -2,7 +2,9 @@
namespace Retailcrm\Retailcrm\Test\Unit\Model\Service;
class IntegrationModuleTest extends \PHPUnit\Framework\TestCase
use Retailcrm\Retailcrm\Test\TestCase;
class IntegrationModuleTest extends TestCase
{
private $mockResourceConfig;
private $mockApiClient;

View file

@ -0,0 +1,126 @@
<?php
namespace Retailcrm\Retailcrm\Test\Unit\Model\Service;
use Retailcrm\Retailcrm\Test\TestCase;
class InventoriesUploadTest extends TestCase
{
private $mockApi;
private $mockProductRepository;
private $mockResponse;
private $mockProduct;
public function setUp()
{
$this->mockApi = $this->getMockBuilder(\Retailcrm\Retailcrm\Helper\Proxy::class)
->disableOriginalConstructor()
->setMethods([
'storeInventories',
'isConfigured'
])
->getMock();
$this->mockProductRepository = $this->getMockBuilder(\Magento\Catalog\Api\ProductRepositoryInterface::class)
->disableOriginalConstructor()
->setMethods(['getById'])
->getMockForAbstractClass();
$this->mockResponse = $this->getMockBuilder(\RetailCrm\Response\ApiResponse::class)
->disableOriginalConstructor()
->setMethods(['isSuccessful'])
->getMock();
$this->mockProduct = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
->disableOriginalConstructor()
->setMethods([
'setStockData',
'save'
])
->getMock();
}
/**
* @param $response
*
* @dataProvider dataProviderLoadStocks
*/
public function testInventoriesUpdload($response)
{
if ($response != false) {
$responseInventories = new \RetailCrm\Response\ApiResponse(200, json_encode($response));
$responseInventories->asJsonResponse($response);
$this->mockResponse->expects($this->any())
->method('isSuccessful')
->willReturn(true);
$this->mockApi->expects($this->any())
->method('isConfigured')
->willReturn(true);
$this->mockApi->expects($this->any())
->method('storeInventories')
->willReturn($responseInventories);
$this->mockProductRepository->expects($this->any())
->method('getById')
->willReturn($this->mockProduct);
} else {
$this->mockResponse->expects($this->any())
->method('isSuccessful')
->willReturn($response);
}
$inventoriesUpload = new \Retailcrm\Retailcrm\Model\Service\InventoriesUpload($this->mockProductRepository, $this->mockApi);
$result = $inventoriesUpload->uploadInventory();
if (!$response['success']) {
$this->assertEquals(false, $result);
} else {
$this->assertEquals(true, $result);
}
}
private function getResponseData()
{
return array(
'true' => $this->getApiInventories(),
'false' => false
);
}
public function dataProviderLoadStocks()
{
$response = $this->getResponseData();
return array(
array(
'response' => $response['true']
),
array(
'response' => $response['false']
)
);
}
private function getApiInventories()
{
return array(
'success' => true,
'pagination' => array(
'limit' => 250,
'totalCount' => 1,
'currentPage' => 1,
'totalPageCount' => 1
),
'offers' => array(
array(
'externalId' => 1,
'xmlId' => 'xmlId',
'quantity' => 10
)
)
);
}
}

View file

@ -2,7 +2,9 @@
namespace Retailcrm\Retailcrm\Test\Unit\Model\Service;
class OrderTest extends \PHPUnit\Framework\TestCase
use Retailcrm\Retailcrm\Test\TestCase;
class OrderTest extends TestCase
{
private $mockProductRepository;
private $mockHelper;
@ -50,11 +52,13 @@ class OrderTest extends \PHPUnit\Framework\TestCase
$this->mockHelper->expects($this->any())->method('getGeneralSettings')
->with('api_version')->willReturn($apiVersion);
$this->mockHelper->expects($this->any())->method('getConfigPayments')->willReturn(['checkmo'=>'test']);
$this->mockHelper->expects($this->any())->method('getCongigStatus')->willReturn(['processing'=>'test']);
$this->mockHelper->expects($this->any())->method('getCongigShipping')->willReturn(['flatrate'=>'test']);
$this->mockConfig->expects($this->any())->method('getValue')
->with($this->logicalOr(
$this->equalTo('retailcrm/retailcrm_status/processing'),
$this->equalTo('retailcrm/retailcrm_payment/checkmo'),
$this->equalTo('retailcrm/retailcrm_shipping/flatrate')
$this->equalTo('retailcrm/retailcrm_site/default')
))->will($this->returnCallback([$this, 'getCallbackDataConfig']));
$mockProduct = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
@ -90,7 +94,14 @@ class OrderTest extends \PHPUnit\Framework\TestCase
$mockShippingAddress = $this->getMockBuilder(\Magento\Sales\Model\Order\Address::class)
->disableOriginalConstructor()
->setMethods(['getData'])
->setMethods([
'getData',
'getTelephone',
'getFirstname',
'getLastname',
'getMiddlename',
'getEmail'
])
->getMock();
$mockShippingAddress->expects($this->any())
->method('getData')
@ -103,11 +114,11 @@ class OrderTest extends \PHPUnit\Framework\TestCase
))
->will($this->returnCallback([$this, 'getCallbackDataAddress']));
$mockBillingAddress = $this->getMockBuilder(\Magento\Sales\Model\Order\Address::class)
->disableOriginalConstructor()
->setMethods(['getTelephone'])
->getMock();
$mockBillingAddress->expects($this->any())->method('getTelephone')->willReturn('89000000000');
$mockShippingAddress->expects($this->any())->method('getTelephone')->willReturn('89000000000');
$mockShippingAddress->expects($this->any())->method('getFirstname')->willReturn('Test');
$mockShippingAddress->expects($this->any())->method('getLastname')->willReturn('Test');
$mockShippingAddress->expects($this->any())->method('getMiddlename')->willReturn('Test');
$mockShippingAddress->expects($this->any())->method('getEmail')->willReturn('test@mail.com');
$mockPaymentMethod = $this->getMockBuilder(\Magento\Payment\Model\MethodInterface::class)
->disableOriginalConstructor()
@ -121,16 +132,11 @@ class OrderTest extends \PHPUnit\Framework\TestCase
$mockPayment->expects($this->any())->method('getMethodInstance')->willReturn($mockPaymentMethod);
$this->mockOrder->expects($this->any())->method('getAllItems')->willReturn([$mockItem]);
$this->mockOrder->expects($this->any())->method('getBillingAddress')->willReturn($mockBillingAddress);
$this->mockOrder->expects($this->any())->method('getShippingAddress')->willReturn($mockShippingAddress);
$this->mockOrder->expects($this->any())->method('getShippingMethod')->willReturn('flatrate_flatrate');
$this->mockOrder->expects($this->any())->method('getId')->willReturn(1);
$this->mockOrder->expects($this->any())->method('getRealOrderId')->willReturn('000000001');
$this->mockOrder->expects($this->any())->method('getCreatedAt')->willReturn(date('Y-m-d H:i:s'));
$this->mockOrder->expects($this->any())->method('getCustomerLastname')->willReturn('Test');
$this->mockOrder->expects($this->any())->method('getCustomerFirstname')->willReturn(date('Test'));
$this->mockOrder->expects($this->any())->method('getCustomerMiddlename')->willReturn(date('Test'));
$this->mockOrder->expects($this->any())->method('getCustomerEmail')->willReturn('test@mail.com');
$this->mockOrder->expects($this->any())->method('getStatus')->willReturn('processing');
$this->mockOrder->expects($this->any())->method('getShippingAmount')->willReturn(100);
$this->mockOrder->expects($this->any())->method('getDiscountAmount')->willReturn(0);
@ -163,9 +169,7 @@ class OrderTest extends \PHPUnit\Framework\TestCase
public function getCallbackDataConfig($key)
{
$data = [
'retailcrm/retailcrm_status/processing' => 'new',
'retailcrm/retailcrm_payment/checkmo' => 'test',
'retailcrm/retailcrm_shipping/flatrate' => 'test'
'retailcrm/retailcrm_site/default' => 'test'
];
return $data[$key];

View file

@ -1,11 +1,11 @@
{
"name": "retailcrm/retailcrm",
"description": "Retailcrm",
"description": "RetailCRM",
"require": {
"retailcrm/api-client-php": "~5.0"
},
"type": "magento2-module",
"version": "2.3.1",
"version": "2.5.2",
"license": [
"OSL-3.0",
"AFL-3.0"

View file

@ -2,7 +2,7 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<tab id="retailcrm" translate="label" sortOrder="10">
<label>Retailcrm</label>
<label>RetailCRM</label>
</tab>
<section id="retailcrm" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
<class>separator-top</class>
@ -18,7 +18,7 @@
</field>
<field id="api_key" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>API key</label>
<comment>You can create an API key in the administration section of retailCRM</comment>
<comment>You can create an API key in the administration section of RetailCRM</comment>
</field>
<field id="api_version" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>API version</label>
@ -34,17 +34,29 @@
<source_model>Retailcrm\Retailcrm\Model\Setting\Attribute</source_model>
</field>
</group>
<group id="shipping" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<group id="shippingList" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Delivery types</label>
<frontend_model>Retailcrm\Retailcrm\Block\Adminhtml\System\Config\Form\Fieldset\Shipping</frontend_model>
<field id="shippingList" translate="label" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
<label>shipping settings</label>
<frontend_model>Retailcrm\Retailcrm\Block\Adminhtml\System\Config\Form\Fieldset\ShippingList</frontend_model>
<backend_model>Magento\Config\Model\Config\Backend\Serialized\ArraySerialized</backend_model>
</field>
</group>
<group id="payment" translate="label comment" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
<group id="paymentList" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Payment types</label>
<frontend_model>Retailcrm\Retailcrm\Block\Adminhtml\System\Config\Form\Fieldset\Payment</frontend_model>
<field id="paymentList" translate="label" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
<label>payment settings</label>
<frontend_model>Retailcrm\Retailcrm\Block\Adminhtml\System\Config\Form\Fieldset\PaymentList</frontend_model>
<backend_model>Magento\Config\Model\Config\Backend\Serialized\ArraySerialized</backend_model>
</field>
</group>
<group id="status" translate="label" type="select" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Order statuses</label>
<frontend_model>Retailcrm\Retailcrm\Block\Adminhtml\System\Config\Form\Fieldset\Status</frontend_model>
<group id="statusList" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Status types</label>
<field id="statusList" translate="label" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
<label>status settings</label>
<frontend_model>Retailcrm\Retailcrm\Block\Adminhtml\System\Config\Form\Fieldset\StatusList</frontend_model>
<backend_model>Magento\Config\Model\Config\Backend\Serialized\ArraySerialized</backend_model>
</field>
</group>
<group id="load" translate="label" type="text" sortOrder="80" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Uploading orders</label>
@ -64,6 +76,23 @@
<label>Setting the stores correspondence</label>
<frontend_model>Retailcrm\Retailcrm\Block\Adminhtml\System\Config\Form\Fieldset\Sites</frontend_model>
</group>
<group id="daemon_collector" translate="label" type="select" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Daemon Collector</label>
<field id="active" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Activate</label>
<source_model>Retailcrm\Retailcrm\Model\Setting\Select</source_model>
</field>
<field id="key" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Site key</label>
</field>
</group>
<group id="inventories_upload" translate="label" type="select" sortOrder="90" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Synchronization of the stock balance</label>
<field id="active" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Activate</label>
<source_model>Retailcrm\Retailcrm\Model\Setting\Select</source_model>
</field>
</group>
</section>
</system>
</config>

View file

@ -4,10 +4,11 @@
<job name="create_icml" instance="Retailcrm\Retailcrm\Cron\Icml" method="execute">
<schedule>* */4 * * *</schedule>
</job>
<job name="order_hystory" instance="Retailcrm\Retailcrm\Cron\OrderHistory" method="execute">
<schedule>*/5 * * * *</schedule>
</job>
<job name="inventories" instance="Retailcrm\Retailcrm\Cron\Inventories" method="execute">
<schedule>*/15 * * * *</schedule>
</job>
</group>
</config>

View file

@ -13,6 +13,7 @@
<argument name="commands" xsi:type="array">
<item name="orders_export_command" xsi:type="object">Retailcrm\Retailcrm\Console\Command\OrdersExport</item>
<item name="customers_export_command" xsi:type="object">Retailcrm\Retailcrm\Console\Command\CustomersExport</item>
<item name="icml_generate_command" xsi:type="object">Retailcrm\Retailcrm\Console\Command\IcmlGenerate</item>
</argument>
</arguments>
</type>

View file

@ -1,7 +1,7 @@
"Settings","La configuración"
"Main settings","La configuración general"
"API key","La llave API"
"You can create an API key in the administration section of retailCRM","Puede crear la llave API en la sección administrativa del retailCRM"
"You can create an API key in the administration section of RetailCRM","Puede crear la llave API en la sección administrativa del RetailCRM"
"API version","La versión API"
"Catalogue settings","La configuración del catálogo"
"Attributes for uploading to ICML","Los atributos para importar al ICML"
@ -15,10 +15,13 @@
"Setting the store by default","La configuración de la tienda por defecto"
"Setting the stores correspondence","La configuración de la concordancia de tienda"
"Enter API of your URL and API key","Introduce el enlace API y la llave API"
"Incorrect URL of retailCRM","La dirección del retailCRM es incorrecto"
"Incorrect URL of RetailCRM","La dirección del RetailCRM es incorrecto"
"Make sure that the entered data is correct","Asegúrese de que los datos introducidos son correctos"
"Incorrect API key","La llave API es incorrecta"
"Incorrect URL of retailCRM or API key","La dirección del retailCRM o la llave API son incorrectos"
"Incorrect URL of RetailCRM or API key","La dirección del RetailCRM o la llave API son incorrectos"
"The selected API version is unavailable","La versión de la API seleccionada no está disponible"
"Send","Enviar"
"Default site","Tienda por defecto"
"Default site","Tienda por defecto"
"Activate","Active"
"Site key","Clave de la página web"
"Synchronization of the stock balance","Sincronizar el stock"
1 Settings La configuración
2 Main settings La configuración general
3 API key La llave API
4 You can create an API key in the administration section of retailCRM You can create an API key in the administration section of RetailCRM Puede crear la llave API en la sección administrativa del retailCRM Puede crear la llave API en la sección administrativa del RetailCRM
5 API version La versión API
6 Catalogue settings La configuración del catálogo
7 Attributes for uploading to ICML Los atributos para importar al ICML
15 Setting the store by default La configuración de la tienda por defecto
16 Setting the stores correspondence La configuración de la concordancia de tienda
17 Enter API of your URL and API key Introduce el enlace API y la llave API
18 Incorrect URL of retailCRM Incorrect URL of RetailCRM La dirección del retailCRM es incorrecto La dirección del RetailCRM es incorrecto
19 Make sure that the entered data is correct Asegúrese de que los datos introducidos son correctos
20 Incorrect API key La llave API es incorrecta
21 Incorrect URL of retailCRM or API key Incorrect URL of RetailCRM or API key La dirección del retailCRM o la llave API son incorrectos La dirección del RetailCRM o la llave API son incorrectos
22 The selected API version is unavailable La versión de la API seleccionada no está disponible
23 Send Enviar
24 Default site Tienda por defecto
25 Activate Active
26 Site key Clave de la página web
27 Synchronization of the stock balance Sincronizar el stock

View file

@ -1,7 +1,7 @@
"Settings","Настройки"
"Main settings","Главные настройки"
"API key","API ключ"
"You can create an API key in the administration section of retailCRM","Вы можете создать API ключ в административном разделе retailCRM"
"You can create an API key in the administration section of RetailCRM","Вы можете создать API ключ в административном разделе RetailCRM"
"API version","Версия API"
"Catalogue settings","Настройки каталога"
"Attributes for uploading to ICML","Атрибуты для выгрузки в ICML"
@ -15,10 +15,13 @@
"Setting the store by default","Настройка магазина по умолчанию"
"Setting the stores correspondence","Настройка соответствия магазинов"
"Enter API of your URL and API key","Введите Ваш API URL и API ключ"
"Incorrect URL of retailCRM","Некорректный адрес retailCRM"
"Incorrect URL of RetailCRM","Некорректный адрес RetailCRM"
"Make sure that the entered data is correct","Убедитесь, что введенные данные верны"
"Incorrect API key","Некорректный API ключ"
"Incorrect URL of retailCRM or API key","Некорректный адрес retailCRM или API ключ"
"Incorrect URL of RetailCRM or API key","Некорректный адрес RetailCRM или API ключ"
"The selected API version is unavailable","Выбранная версия API недоступна"
"Send","Выгрузить"
"Default site","Сайт по умолчанию"
"Default site","Сайт по умолчанию"
"Activate","Активировать"
"Site key","Ключ сайта"
"Synchronization of the stock balance","Синхронизация остатков"
1 Settings Настройки
2 Main settings Главные настройки
3 API key API ключ
4 You can create an API key in the administration section of retailCRM You can create an API key in the administration section of RetailCRM Вы можете создать API ключ в административном разделе retailCRM Вы можете создать API ключ в административном разделе RetailCRM
5 API version Версия API
6 Catalogue settings Настройки каталога
7 Attributes for uploading to ICML Атрибуты для выгрузки в ICML
15 Setting the store by default Настройка магазина по умолчанию
16 Setting the stores correspondence Настройка соответствия магазинов
17 Enter API of your URL and API key Введите Ваш API URL и API ключ
18 Incorrect URL of retailCRM Incorrect URL of RetailCRM Некорректный адрес retailCRM Некорректный адрес RetailCRM
19 Make sure that the entered data is correct Убедитесь, что введенные данные верны
20 Incorrect API key Некорректный API ключ
21 Incorrect URL of retailCRM or API key Incorrect URL of RetailCRM or API key Некорректный адрес retailCRM или API ключ Некорректный адрес RetailCRM или API ключ
22 The selected API version is unavailable Выбранная версия API недоступна
23 Send Выгрузить
24 Default site Сайт по умолчанию
25 Activate Активировать
26 Site key Ключ сайта
27 Synchronization of the stock balance Синхронизация остатков

View file

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="head.additional">
<block class="Retailcrm\Retailcrm\Block\Frontend\DaemonCollector" name="block_name" template="Retailcrm_Retailcrm::daemon_collector.phtml" />
</referenceBlock>
</body>
</page>

View file

@ -3,4 +3,9 @@
<referenceContainer name="content">
<block class="Retailcrm\Retailcrm\Block\Display" name="retailcrm_display" template="Retailcrm_Retailcrm::sayhello.phtml" />
</referenceContainer>
<body>
<referenceBlock name="head.additional">
<block class="Retailcrm\Retailcrm\Block\Frontend\DaemonCollector" name="block_name" template="Retailcrm_Retailcrm::daemon_collector.phtml" />
</referenceBlock>
</body>
</page>

View file

@ -0,0 +1 @@
<?php echo $block->buildScript()->getJs() ?>