Commit e986de77 authored by Telenkov Ruslan's avatar Telenkov Ruslan

shipping

parent 7ac9af42
......@@ -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",
......
This diff is collapsed.
services:
ajax.node_entity:
class: Drupal\ajax\Normalizer\NodeEntityNormalizer
arguments: ['@entity_type.manager']
tags:
- { name: normalizer, priority: 8 }
......@@ -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));*/
......
<?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;
}
}
name: Check
package: Custom
type: module
core_version_requirement: ^8.8 || ^9
<?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;
}
//}
}
}
name: Commerce chekout
package: Custom
type: module
core_version_requirement: ^8.8 || ^9
<?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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment