Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #1

Merged
merged 3 commits into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
# magento-backend-test
# Durstexpress Magento Test

### Your task:
0. Setup environment as described in next section ( see [setup](#setup))

1. Create a Magento module Dex_PriceCalculation.

2. Add to admin panel new admin configuration field under Dex module(Dex_PriceCalculation) backend config section that is saving integer value

3. Whenever user add product to a cart multiply it’s price with value saved in admin panel

4. (Optional) Add 50% discount to product price on checkout without using voucher.

5.(Good to have it) Add a Integration test for the Magento module Dex_PriceCalculation.

As result we are expecting to receive pull request with name in format <TEST-YOUR_NAME>. you should not spend more
than 3-4 hours on the test it is not necessary to finish all of it. we want to evalute your knowledge related to Magento


### Setup

##### 1. Clone project
```bash
git clone git@github.com:Durstexpress/magento-backend-test.git
```
##### 2. run `bin/start` and `bin/setup` and update run magento provision commands if needed

Prerequisites :This setup assumes you are running Docker


##### 3. You are done. Now you can test service by url after setting up etc/hosts [https://magento2.test/](https://magento2.test/)




2 changes: 2 additions & 0 deletions bin/bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
bin/cli bash
3 changes: 3 additions & 0 deletions bin/cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
docker-compose exec phpfpm "$@"
3 changes: 3 additions & 0 deletions bin/clinotty
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
docker-compose exec -T phpfpm "$@"
2 changes: 2 additions & 0 deletions bin/composer
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
bin/cli composer "$@"
11 changes: 11 additions & 0 deletions bin/copyfromcontainer
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify a directory or file to copy from container (ex. vendor, --all)" && exit

REAL_SRC=$(cd -P "src" && pwd)
if [ "$1" == "--all" ]; then
docker cp $(docker-compose ps -q phpfpm|awk '{print $1}'):/var/www/html/./ $REAL_SRC/
echo "Completed copying all files from container to host"
else
docker cp $(docker-compose ps -q phpfpm|awk '{print $1}'):/var/www/html/$1 $REAL_SRC/
echo "Completed copying $1 from container to host"
fi
15 changes: 15 additions & 0 deletions bin/copytocontainer
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify a directory or file to copy to container (ex. vendor, --all)" && exit

REAL_SRC=$(cd -P "src" && pwd)
if [ "$1" == "--all" ]; then
docker cp $REAL_SRC/./ $(docker-compose ps -q phpfpm|awk '{print $1}'):/var/www/html/
echo "Completed copying all files from host to container"
bin/fixowns
bin/fixperms
else
docker cp $REAL_SRC/$1 $(docker-compose ps -q phpfpm|awk '{print $1}'):/var/www/html/$1
echo "Completed copying $1 from host to container"
bin/fixowns $1
bin/fixperms $1
fi
13 changes: 13 additions & 0 deletions bin/dev-urn-catalog-generate
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
bin/magento dev:urn-catalog:generate misc.xml
bin/copyfromcontainer misc.xml

REAL_SRC=$(cd -P "src" && pwd)

sed -i .bak "s?/var/www/html?$PROJECT_DIR$/src?g" $REAL_SRC/misc.xml
rm $REAL_SRC/misc.xml.bak

mkdir -p $REAL_SRC/.idea
mv $REAL_SRC/misc.xml $REAL_SRC/.idea/misc.xml

echo "URN's have been generated, you may now restart PHPStorm"
2 changes: 2 additions & 0 deletions bin/devconsole
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
bin/cli bin/n98-magerun2.phar dev:console
9 changes: 9 additions & 0 deletions bin/download
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify the version to download (ex. 2.0.0)" && exit
if [ ! -f ~/.docker-magento/magento2-$1.tar.gz ]; then
mkdir -p ~/.docker-magento
(cd ~/.docker-magento && curl -OL http://pubfiles.nexcess.net/magento/ce-packages/magento2-$1.tar.gz)
fi

echo "Extracting magento2-$1.tar.gz to ./src"
mkdir -p src && tar xzf ~/.docker-magento/magento2-$1.tar.gz -o -C src
10 changes: 10 additions & 0 deletions bin/fixowns
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
echo "Correcting filesystem ownerships..."

if [ -z "$1" ]; then
bin/rootnotty chown -R app:app /var/www/
else
bin/rootnotty chown -R app:app /var/www/html/$1
fi

echo "Filesystem ownerships corrected."
13 changes: 13 additions & 0 deletions bin/fixperms
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
echo "Correcting filesystem permissions..."

if [ -z "$1" ]; then
bin/clinotty find var vendor pub/static pub/media app/etc -type f -exec chmod u+w {} \;
bin/clinotty find var vendor pub/static pub/media app/etc -type d -exec chmod u+w {} \;
bin/clinotty chmod u+x bin/magento
else
bin/clinotty find $1 -type f -exec chmod u+w {} \;
bin/clinotty find $1 -type d -exec chmod u+w {} \;
fi

echo "Filesystem permissions corrected."
2 changes: 2 additions & 0 deletions bin/grunt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
bin/cli grunt "$@"
2 changes: 2 additions & 0 deletions bin/magento
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
bin/cli bin/magento "$@"
2 changes: 2 additions & 0 deletions bin/n98-magerun2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
bin/cli bin/n98-magerun2.phar "$@"
2 changes: 2 additions & 0 deletions bin/node
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
bin/cli node "$@"
2 changes: 2 additions & 0 deletions bin/npm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
bin/cli npm "$@"
8 changes: 8 additions & 0 deletions bin/pwa-studio
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
if [ ! -d pwa-studio ]; then
echo "PWA studio must first be installed by running bin/setup-pwa-studio"
exit
fi

cd pwa-studio
NODE_TLS_REJECT_UNAUTHORIZED=0 yarn run watch:all
2 changes: 2 additions & 0 deletions bin/redis
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
docker-compose exec redis "$@"
2 changes: 2 additions & 0 deletions bin/remove
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
docker-compose rm
6 changes: 6 additions & 0 deletions bin/removevolumes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
declare -l current_folder
current_folder=${PWD##*/}
docker volume rm ${current_folder}_appdata
docker volume rm ${current_folder}_dbdata
docker volume rm ${current_folder}_sockdata
3 changes: 3 additions & 0 deletions bin/restart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
bin/stop
bin/start
3 changes: 3 additions & 0 deletions bin/root
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
docker-compose exec -u root phpfpm "$@"
3 changes: 3 additions & 0 deletions bin/rootnotty
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
docker-compose exec -u root -T phpfpm "$@"
105 changes: 105 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/bin/bash
BASE_URL=${1:-magento2.test}

bin/stop

# fix for invalid google-shopping-api checksum contained in archive installs (temporary fix until nexcess archive is patched)
sed -e 's/5f5929ef9f2ec4ca048a2add261d22c92807630f/ce31e720d60451784b9fdb3769e43e149f50d436/' src/composer.lock > composer.lock && mv composer.lock src/composer.lock

docker-compose -f docker-compose.yml up -d
sleep 1 #Ensure containers are started...

curl -O https://files.magerun.net/n98-magerun2.phar
chmod +x n98-magerun2.phar
mv n98-magerun2.phar src/bin/n98-magerun2.phar

echo "Copying all files from host to container..."
rm -rf src/vendor #Clear for step below
bin/copytocontainer --all

bin/clinotty chmod u+x bin/magento

if hash composer 2>/dev/null; then
PUBLIC_KEY="$(composer config -gl | grep '\[http-basic.repo.magento.com.username\]' | cut -c40-)"
PRIVATE_KEY="$(composer config -gl | grep '\[http-basic.repo.magento.com.password\]' | cut -c40-)"
fi

if [ -z "$PUBLIC_KEY" ] || [ -z "$PRIVATE_KEY" ]; then
exec < /dev/tty
echo
echo
echo " Authentication required (repo.magento.com, public_key and private_key):"
read -p " Username: " PUBLIC_KEY
read -p " Password: " PRIVATE_KEY
echo
if [ -n "$PUBLIC_KEY" ] && [ -n "$PRIVATE_KEY" ] && hash composer 2>/dev/null; then
read -p " Add authentication information to host composer config? y/n: " ADD_AUTH
echo
if [[ $ADD_AUTH =~ ^[Yy]$ ]]; then
composer global config http-basic.repo.magento.com $PUBLIC_KEY $PRIVATE_KEY
fi
ADD_AUTH=''
fi
exec <&-
fi

if [ -n "$PUBLIC_KEY" ] && [ -n "$PRIVATE_KEY" ]; then
bin/clinotty composer config http-basic.repo.magento.com $PUBLIC_KEY $PRIVATE_KEY
PUBLIC_KEY=''
PRIVATE_KEY=''
fi

echo "Forcing reinstall of composer deps to ensure perms & reqs..."
bin/clinotty composer global require hirak/prestissimo
bin/clinotty composer install

bin/clinotty bin/magento setup:install \
--db-host=db \
--db-name=magento \
--db-user=magento \
--db-password=magento \
--base-url=https://$BASE_URL/ \
--admin-firstname=John \
--admin-lastname=Smith \
--admin-email=john.smith@gmail.com \
--admin-user=john.smith \
--admin-password=password123 \
--language=en_US \
--currency=USD \
--timezone=America/New_York \
--amqp-host=rabbitmq \
--amqp-port=5672 \
--amqp-user=guest \
--amqp-password=guest \
--amqp-virtualhost=/ \
--use-rewrites=1

echo "Turning on developer mode.."
bin/clinotty bin/magento deploy:mode:set developer

bin/clinotty bin/magento indexer:reindex

echo "Forcing deploy of static content to speed up initial requests..."
bin/clinotty bin/magento setup:static-content:deploy -f

echo "Enabling Redis for cache..."
bin/clinotty bin/magento setup:config:set --no-interaction --cache-backend=redis --cache-backend-redis-server=redis --cache-backend-redis-db=0

echo "Enabling Redis for Full Page Cache..."
bin/clinotty bin/magento setup:config:set --no-interaction --page-cache=redis --page-cache-redis-server=redis --page-cache-redis-db=1

echo "Enabling Redis for session..."
bin/clinotty bin/magento setup:config:set --no-interaction --session-save=redis --session-save-redis-host=redis --session-save-redis-log-level=4 --session-save-redis-db=2

echo "Clearing the cache for good measure..."
bin/clinotty bin/magento cache:flush

echo "Copying files from container to host after install..."
bin/copyfromcontainer app
bin/copyfromcontainer vendor

echo "Generating SSL certificate..."
bin/setup-ssl $BASE_URL

echo "Docker development environment setup complete."
echo "You may now access your Magento instance at https://${BASE_URL}/"
9 changes: 9 additions & 0 deletions bin/setup-pwa-studio
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
echo "Install NodeJS and Yarn on host machine, otherwise setup will fail"

BASE_URL=${1:-master-7rqtwti-mfwmkrjfqvbjk.us-4.magentosite.cloud}
git clone https://github.com/magento/pwa-studio.git
cd pwa-studio
yarn install
yarn buildpack create-custom-origin packages/venia-concept
MAGENTO_BACKEND_URL="https://$BASE_URL/" yarn buildpack create-env-file packages/venia-concept
17 changes: 17 additions & 0 deletions bin/setup-ssl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify a domain (ex. mydomain.test)" && exit

# Generate certificate authority if not already setup
if ! docker-compose exec -u root app cat /root/.local/share/mkcert/rootCA.pem | grep -q 'BEGIN CERTIFICATE'; then
bin/setup-ssl-ca
fi

# Generate the certificate for the specified domain
docker-compose exec -u root app mkcert -key-file nginx.key -cert-file nginx.crt "$@"
echo "Moving key and cert to /etc/nginx/certs/..."
docker-compose exec -u root app chown app:app nginx.key nginx.crt
docker-compose exec -u root app mv nginx.key nginx.crt /etc/nginx/certs/

# Restart nginx to apply the updates
echo "Restarting containers to apply updates..."
bin/restart
6 changes: 6 additions & 0 deletions bin/setup-ssl-ca
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
docker-compose exec -u root app mkcert -install
docker cp $(docker-compose ps -q app|awk '{print $1}'):/root/.local/share/mkcert/rootCA.pem .
echo "System password requested to install certificate authority on host..."
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain rootCA.pem
rm rootCA.pem
9 changes: 9 additions & 0 deletions bin/start
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d

## Blackfire support
# ------------------
## First register the blackfire agent with:
#bin/root blackfire-agent --register --server-id={YOUR_SERVER_ID} --server-token={YOUR_SERVER_TOKEN}
## Then uncomment the below line (and leave uncommented) to start the agent automatically with bin/start:
#bin/root /etc/init.d/blackfire-agent start
2 changes: 2 additions & 0 deletions bin/status
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
docker-compose ps
2 changes: 2 additions & 0 deletions bin/stop
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
docker-compose -f docker-compose.yml -f docker-compose.dev.yml stop
8 changes: 8 additions & 0 deletions bin/update
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
mkdir -p tmpupdate && cd $_
curl -s https://raw.githubusercontent.com/markshust/docker-magento/master/lib/template | bash
rm -rf .git
rsync -av ./ ../
cd ..
rm -rf tmpupdate
echo "docker-magento has been updated, run bin/restart to apply the updates"
12 changes: 12 additions & 0 deletions bin/xdebug
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
if [ "$1" == "disable" ]; then
bin/cli sed -i -e 's/^zend_extension/\;zend_extension/g' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
bin/restart
echo "Xdebug has been disabled."
elif [ "$1" == "enable" ]; then
bin/cli sed -i -e 's/^\;zend_extension/zend_extension/g' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
bin/restart
echo "Xdebug has been enabled."
else
echo "Please specify either 'enable' or 'disable' as an argument"
fi
34 changes: 34 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Mark Shust's Docker Configuration for Magento (https://github.com/markshust/docker-magento)
# Version 29.0.0

version: "3"

services:
app:
volumes: &appvolumes
# Host mounts with performance penalty, only put what is necessary here
- ./src/app/code:/var/www/html/app/code:delegated
- ./src/app/design:/var/www/html/app/design:delegated
- ./src/app/etc:/var/www/html/app/etc:delegated
- ./src/composer.json:/var/www/html/composer.json:delegated
- ./src/composer.lock:/var/www/html/composer.lock:delegated
- ./src/nginx.conf.sample:/var/www/html/nginx.conf:delegated
#- ./src/var/log:/var/www/html/var/log:delegated
#- ./src/var/report:/var/www/html/var/report:delegated

phpfpm:
volumes: *appvolumes
# Linux only: host.docker.internal doesn't exist https://github.com/docker/for-linux/issues/264
# Uncomment two lines below & replace IP with result of: docker run --rm alpine ip route | awk 'NR==1 {print $3}'
#extra_hosts:
# - "host.docker.internal:IP"

mailhog:
image: mailhog/mailhog
ports:
- "1025"
- "8025:8025"

# Disabling cron by default as it uses higher CPU, enable if needed
#cron:
# volumes: *appvolumes