Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
store
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
Telenkov Ruslan
store
Commits
e986de77
Commit
e986de77
authored
Jun 24, 2022
by
Telenkov Ruslan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
shipping
parent
7ac9af42
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
379 additions
and
50 deletions
+379
-50
composer.json
app/composer.json
+3
-0
composer.lock
app/composer.lock
+252
-1
ajax.services.yml
app/docroot/modules/custom/ajax/ajax.services.yml
+6
-0
modal_form.js
app/docroot/modules/custom/ajax/js/modal_form.js
+2
-49
NodeEntityNormalizer.php
...dules/custom/ajax/src/Normalizer/NodeEntityNormalizer.php
+52
-0
check.info.yml
app/docroot/modules/custom/check/check.info.yml
+4
-0
check.module
app/docroot/modules/custom/check/check.module
+47
-0
commerce_chekout.info.yml
...modules/custom/commerce_chekout/commerce_chekout.info.yml
+4
-0
commerce_chekout.module
...t/modules/custom/commerce_chekout/commerce_chekout.module
+9
-0
No files found.
app/composer.json
View file @
e986de77
...
...
@@ -16,12 +16,15 @@
"drupal/admin_toolbar"
:
"^2.4"
,
"drupal/commerce"
:
"^2.30"
,
"drupal/commerce_cart_api"
:
"^1.5"
,
"drupal/commerce_shipping"
:
"^2.4"
,
"drupal/commerce_stock"
:
"^1.0"
,
"drupal/config_ignore"
:
"^2.3"
,
"drupal/core"
:
"^9.1"
,
"drupal/core-composer-scaffold"
:
"^9"
,
"drupal/devel"
:
"^4.0"
,
"drupal/devel_php"
:
"^1.0"
,
"drupal/module_filter"
:
"^3.1"
,
"drupal/restui"
:
"^1.20"
,
"drush/drush"
:
"^10.3"
,
"hirak/prestissimo"
:
"^0.3.7"
,
"webflo/drupal-finder"
:
"^0|^1.0.0"
,
...
...
app/composer.lock
View file @
e986de77
This diff is collapsed.
Click to expand it.
app/docroot/modules/custom/ajax/ajax.services.yml
0 → 100644
View file @
e986de77
services
:
ajax.node_entity
:
class
:
Drupal\ajax\Normalizer\NodeEntityNormalizer
arguments
:
[
'
@entity_type.manager'
]
tags
:
-
{
name
:
normalizer
,
priority
:
8
}
app/docroot/modules/custom/ajax/js/modal_form.js
View file @
e986de77
...
...
@@ -12,7 +12,8 @@
// total.push(currentValue.total_price.formatted);
currentValue
.
order_items
.
forEach
(
// перебираем все элементы массива array
function
Items
(
currentItem
)
{
totalarray
.
push
(
currentItem
.
title
+
"<br>"
+
currentItem
.
quantity
+
"<br>"
+
currentValue
.
total_price
.
formatted
+
"<br>"
);
totalarray
.
push
(
"<image src='"
+
currentItem
.
purchased_entity
.
image_url
+
"'>"
+
"<br>"
+
currentItem
.
title
+
"<br>"
+
currentItem
.
quantity
+
"<br>"
+
currentValue
.
total_price
.
formatted
+
"<br>"
);
//title1.push(currentItem.title);
//quantity.push(currentItem.quantity);
// присваивает
...
...
@@ -50,54 +51,6 @@ Drupal.behaviors.block = {
attach: function (context, settings) {
jQuery(document, context).once('block').each( function() {
var totalarray = [];
var title1 = [];
var quantity =[];
var total =[];
var title2 ='';
var request = new XMLHttpRequest();
request.open("GET", "http://store.loc/cart?_format=json");
request.send();
request.onload = function (){
let test = JSON.parse(request.response);
test.forEach( // перебираем все элементы массива array
function sumNumber( currentValue ) {
console.log(currentValue);
total.push(currentValue.total_price.formatted);
currentValue.order_items.forEach( // перебираем все элементы массива array
function Items( currentItem ) {
totalarray.push(currentItem.title+"<br>"+currentItem.quantity+"<br>"+currentValue.total_price.formatted+"<br>");
//title1.push(currentItem.title);
//quantity.push(currentItem.quantity);
// присваивает
}
);
title2 = title1.toString();
}
);
var frontpageModal = Drupal.dialog("<div>"+totalarray+"</div>",{
title: 'Modal on frontpage',
dialogClass: 'front-modal',
width: 400,
height: 400,
autoResize: true,
close: function (event) {
// Удаляем элемент который использовался для содержимого.
jquery(event.target).remove();
}
});
// Отображает модальное окно с overlay.
frontpageModal.showModal();
// Вы также можете использовать
// frontpageModal.show();
// чтобы отобразить модальное окно без overlay, и все элементы за
// модальным окном останутся активными.
}
});
}
}
} (jQuery, Drupal, drupalSettings));*/
...
...
app/docroot/modules/custom/ajax/src/Normalizer/NodeEntityNormalizer.php
0 → 100644
View file @
e986de77
<?php
namespace
Drupal\ajax\Normalizer
;
use
Drupal\commerce_order\Entity\Order
;
use
Drupal\commerce_product\Entity\ProductVariation
;
use
Drupal\file\Entity\File
;
use
Drupal\node\Entity\Node
;
use
Drupal\node\NodeInterface
;
use
Drupal\serialization\Normalizer\ContentEntityNormalizer
;
class
NodeEntityNormalizer
extends
ContentEntityNormalizer
{
/**
* {@inheritdoc}
*/
public
function
__construct
()
{
$this
->
supportedInterfaceOrClass
=
ProductVariation
::
class
;
}
public
function
normalize
(
$object
,
$format
=
NULL
,
array
$context
=
[])
{
//получаю небходимые атрибуты при обращении к апи корзины, в моем случае - при добавлении в корзину вариации продукта коммерса.
$attributes
=
parent
::
normalize
(
$object
,
$format
,
$context
);
//получаю продукт коммерца, в котором хранится ссылка на нужную ноду, где нужно взять картинку
$node
=
\Drupal
::
entityTypeManager
()
->
getStorage
(
'commerce_product'
)
->
loadByProperties
([
'type'
=>
'odezhda'
,
'product_id'
=>
$attributes
[
'product_id'
],
]);
// получаю конкретную ноду продукта коммерца , чтобы не использовать foreach для одного элемента ( т к id у нас в единственном экз)
$product
=
$node
[
$attributes
[
'product_id'
]];
// получаю ноду продукта
$node
=
\Drupal
::
entityTypeManager
()
->
getStorage
(
'node'
)
->
loadByProperties
([
'type'
=>
'products'
,
'nid'
=>
$product
->
field_products
->
target_id
,
]);
$conc_product
=
$node
[
$product
->
field_products
->
target_id
];
// получаю id картинки
$image_id
=
$conc_product
->
field_image
->
target_id
;
//получаю url картинки
$first_file
=
File
::
load
(
$image_id
);
$first_url
=
$first_file
->
createFileUrl
();
//создаю поле картинки в апи ответе корзины
$attributes
[
'image_url'
]
=
$first_url
;
return
$attributes
;
}
}
app/docroot/modules/custom/check/check.info.yml
0 → 100644
View file @
e986de77
name
:
Check
package
:
Custom
type
:
module
core_version_requirement
:
^8.8 || ^9
app/docroot/modules/custom/check/check.module
0 → 100644
View file @
e986de77
<?php
use
Drupal\Core\Form\FormStateInterface
;
/**
* Implements hook_form_alter().
*/
function
check_form_alter
(
&
$form
,
\Drupal\Core\Form\FormStateInterface
$form_state
,
$form_id
)
{
if
(
$form_id
==
'commerce_checkout_flow_multistep_default'
){
//убираю ненужные поля с формы
$form
[
'shipping_information'
][
'shipping_profile'
]
=
null
;
$form
[
'shipping_information'
][
'recalculate_shipping'
]
=
null
;
//if ($form_state->getUserInput()['shipping_information']['shipments'][0]['shipping_method'][0] == '2--default'){
//добавляю поле с адресом и прикручиваю стейты по радиокнопкам (наше в консоли разраба)
$form
[
'shipping_information'
][
'site_address'
]
=
array
(
'#type'
=>
'textfield'
,
'#title'
=>
(
'Site address:'
),
'#states'
=>
array
(
'visible'
=>
array
(
':input[name = "shipping_information[shipments][0][shipping_method][0]"]'
=>
array
(
'value'
=>
'2--default'
,
),
),
),
);
// по айди магазина получаю магазин
$formTest
=
$form_state
->
getBuildInfo
()[
'callback_object'
];
$store
=
\Drupal
::
entityTypeManager
()
->
getStorage
(
'commerce_store'
)
->
loadByProperties
([
'type'
=>
'online'
,
'store_id'
=>
$formTest
->
getOrder
()
->
get
(
'store_id'
)
->
target_id
,
]);
// получаю связанную сущность - склады
$stocks
=
$store
[
$formTest
->
getOrder
()
->
get
(
'store_id'
)
->
target_id
]
->
field_stocks
->
referencedEntities
();
// прохожусь по складам
foreach
(
$stocks
as
$stock
){
$concr_stock
[]
=
$stock
->
get
(
'name'
)
->
value
;
}
//}
}
}
app/docroot/modules/custom/commerce_chekout/commerce_chekout.info.yml
0 → 100644
View file @
e986de77
name
:
Commerce chekout
package
:
Custom
type
:
module
core_version_requirement
:
^8.8 || ^9
app/docroot/modules/custom/commerce_chekout/commerce_chekout.module
0 → 100644
View file @
e986de77
<?php
use
Drupal\Core\Form\FormStateInterface
;
/**
* Implements hook_form_alter().
*/
function
commerce_chekout_form_alter
(
&
$form
,
\Drupal\Core\Form\FormStateInterface
$form_state
,
$form_id
)
{
$a
=
1
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment