MenuItem::make('Импорт товаров',
CustomPage::make('Excel import', 'product-import', 'admin.import.import_product', fn() => [])
)->icon('heroicons.document-arrow-down'),
@if (session('status'))
<x-moonshine::alert type="success" removable="true">{{ session('status') }}</x-moonshine::alert>
@endif
@if (isset($errors) && $errors->any())
<x-moonshine::alert type="error">
@foreach ($errors->all() as $error)
{{ $error }}
@endforeach
</x-moonshine::alert>
@endif
<form action="{{route('import.product')}}" method="post" enctype="multipart/form-data">
@csrf
<div class="grid grid-cols-12 gap-6">
<div class="space-y-6 col-span-12 xl:col-span-6">
<div class="box">
<h2 class="box-title">Импорт данных товаров из EXCEL - файла</h2>
<div class="grid grid-cols-12 gap-6">
<div class="form-group space-y-6 col-span-12 xl:col-span-9" x-show="true" id="wrapper_">
<label class="form-label" for="file">
Excel файл
</label>
<div class="form-group form-group-dropzone">
<input class="form-input form-file-upload" type="file" name="file" accept="*/*">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="space-y-6 col-span-12 xl:col-span-12">
<div class="mt-3 flex w-full flex-wrap justify-start gap-2">
<button type="submit" class="btn btn-primary form_submit_button">Отправить</button>
</div>
</div>
</form>
Route::post('/moonshine/product-import', [App\Http\Controllers\Admin\Import\ImportController::class, 'importProduct'])->name('import.product');
А вообще MoonShine имеет довольно большое и дружелюбное комьюнити, где сами разработчики и опытные пользователи быстро помогаю решать различные задачи, дают советы и отвечаю на вопросы. Тут можно получить ответы на вопросы связанные с MoonShine - t.me/laravel_chat
<Files ~ "^(html_editor_action|mail_entry|upload)\.php$>
deny from all
</Files>
<div id="content_features" class="ty-wysiwyg-content content-features">
<div class="ty-product-feature">
<div class="ty-product-feature__label">Ширина:</div>
<div class="ty-product-feature__value">1400<span class="ty-product-feature__suffix"> мм</span></div>
</div>
<div class="ty-product-feature">
<div class="ty-product-feature__label">Высота:</div>
<div class="ty-product-feature__value">1345<span class="ty-product-feature__suffix"> мм</span></div>
</div>
<div class="ty-product-feature">
<div class="ty-product-feature__label">Глубина:</div>
<div class="ty-product-feature__value">880<span class="ty-product-feature__suffix"> мм</span></div>
</div>
</div>
propsBody = []
try:
propsBody = soup.find('div', {'id' : 'content_features'}).findAll('div', class_='ty-product-feature')
except:
pass
if len(propsBody) > 0:
#self.properties.clear()
propsItems = []
for props in propsBody:
item = {
'label' : props.find('div', class_='ty-product-feature__label').get_text(strip=True),
'value' : props.find('div', class_='ty-product-feature__value').get_text(strip=True)
}
propsItems.append(item)
self.properties = propsItems
[{"label": "Высота:", "value": "220мм"},
{"label": "Глубина:", "value": "295мм"},
{"label": "Материал:", "value": "Сталь"},
{"label": "Вес:", "value": "4,3кг"},
{"label": "Длина:", "value": "650мм"}]
class ExcelFile:
data = {}
labels = set() # множество, перменная, свойство для названий характеристик товаров
def __init__(self, data):
self.data = data
def get(self):
# В цикле проходим по данным полученным в результате парсинга,
# и собираем названия характеристик в множество
for item in self.data:
if len(item['properties']) > 0:
for prop in item['properties']:
self.labels.add(prop['label'])
book = openpyxl.Workbook()
sheet = book.active
# Поля, колонки Excel - файла, для разных данных товаров
sheet['A1'].value = 'src'
sheet['B1'].value = 'name'
sheet['C1'].value = 'category'
sheet['D1'].value = 'art_namber'
sheet['E1'].value = 'price'
sheet['F1'].value = 'main'
sheet['G1'].value = 'more'
sheet['H1'].value = 'descrip'
sheet['I1'].value = 'JSON_properties'
sheet['J1'].value = 'video'
sheet['K1'].value = 'docs'
# Добавляем дополнительные колонки в Excel из названий характеристик
if len(self.labels) > 0:
nam = 12
for nameProp in self.labels:
sheet.cell(row=1, column=nam, value=nameProp)
nam += 1
row = 2
# Записываем в строки Excel- файла данные товаров
for res in self.data:
sheet[row][0].value = res['src']
sheet[row][1].value = res['name']
sheet[row][2].value = res['category']
sheet[row][3].value = res['art_namber']
sheet[row][4].value = res['price']
sheet[row][5].value = res['main']
sheet[row][6].value = ','.join(res['more'])
sheet[row][7].value = res['descrip']
sheet[row][8].value = res['json']
sheet[row][9].value = ','.join(res['video'])
sheet[row][10].value = ','.join(res['docs'])
# Записываем значения характеристик товара в соответствующие названиям колонки Excel- файла
if len(self.labels) > 0:
namberCell = 12
while namberCell < len(self.labels) + 12:
propLabel = sheet.cell(row=1, column=namberCell).value
for property in res['properties']:
if property['label'] == propLabel:
sheet.cell(row=row, column=namberCell).value = property['value']
else:
sheet.cell(row=row, column=namberCell)
namberCell += 1
row += 1
file_name = detNameExcelFile()
book.save(file_name)
book.close()
return file_name
UseCanonicalName Off
<If "tolower(%{SERVER_NAME}) != 'my-site.ru'">
AllowOverride None
Require all denied
</If>
<?
//если если ранее по коду модуль инфоблока не подключен, то подключаем его
CModule::IncludeModule("iblock");
$iblock_id = 3; // Цифровое значение ID - Вашего Инфоблока - каталога товаров
$arFilter = Array("IBLOCK_ID"=>$iblock_id, "ACTIVE"=>"Y");
$count_goods = CIBlockElement::GetList(Array(), $arFilter, Array(), false, Array());
?>
Количество товаров: <? echo $count_goods; ?>
$currency = Currency::select('currency', 'Nominal', 'value')->get()->keyBy('currency')->toArray();
$countUpdate = DB::update("UPDATE `product` SET `price` = (`base_price` * ?) WHERE `currency`='EUR'", [ $currency['EUR']['value'] ]);
$category::fixTree();
[Fri Nov 13 12:35:33.249913 2020] [proxy_fcgi:error] [pid 18854:tid 140666176743168] [client 212.45.19.58:43938] AH01071: Got error 'PHP message: PHP Deprecated: The mbstring.func_overload directive is deprecated in Unknown on line 0', referer: http://hight-control.ru/
//Pechnik - модель/таблица содержит данные поста
//Images - модель/таблица содержит информацию о изображениях галереи
// - метод ресурсного контролера для удаления поста
public function destroy($id)
{
$images = Images::where('pechnik_id', $id); //получаю колекцию файлов галереи превязанных к ID поста p из таблицы Images
$pathImages = $images->get('img'); //получаю данные наименование и путь файлов галереи превязанных к ID поста
if (!$pathImages->isEmpty()){
foreach ($pathImages as $img){
$path = $img->img;
Storage::disk('public')->delete(str_replace('storage', '', $path)); //в цикле удаляю фалы галереи превязанных к ID поста
}
}
$images->delete(); // удаляю записи в таблице Images:: о файлах галереи
$pechnik= Pechnik::find($id); // получаю данные поста по ID из таблицы Pechnik::
Pechnik::find($id)->delete(); // удаляю запись в таблице Pechnik:: - данные поста
return redirect()->route('admin.index')->with('success', 'Информаця успешно удалена');
}
"USE_FILTER" => "Y",
"FILTER_NAME" => "arrFilterAdvice",
<? $GLOBALS['arrFilterAdvice'] = array('ACTIVE' => 'Y', '!PROPERTY_STICKERS' => false);
$APPLICATION->IncludeComponent(
"bitrix:catalog.section",
"shop_window",
array(
…
"USE_FILTER" => "Y",
"FILTER_NAME" => "arrFilterAdvice",
…
if(!$arResult["ADVICE"]){
foreach($arResult["ITEMS"] as $Element){
foreach($Element["PROPERTIES"]["STICKERS"]["VALUE_XML_ID"] as $type){
if($type == "HIT") $arResult["ADVICE"]["HIT"][$Element["ID"]] = $Element;
if($type == "RECOMMEND") $arResult["ADVICE"]["RECOMMEND"][$Element["ID"]] = $Element;
if($type == "NEW") $arResult["ADVICE"]["NEW"][$Element["ID"]] = $Element;
if($type == "STOCK") $arResult["ADVICE"]["STOCK"][$Element["ID"]] = $Element;
}
}
}
$cp = $this->__component;
if (is_object($cp))
{
$cp->arResult["ASSOCIATED"] = $arResult["PROPERTIES"]["ASSOCIATED"]["VALUE"];
$cp->SetResultCacheKeys(array("ASSOCIATED")); //cache keys in $arResult array
}
$templateData["ASSOCIATED"] = $arResult["PROPERTIES"]["ASSOCIATED"]["VALUE"];
function funcItemsHeight(domItem) {
var menuItems = document.querySelectorAll(domItem);
var top = menuItems[0].offsetTop;
var arrHeight = [];
var arrItems = [];
for (var i = 0; i < menuItems.length; i++) {
menuItems[i].style.height = 'auto';
}
for (var i = 0; i < menuItems.length; i++) {
if (top != menuItems[i].offsetTop) {
arrHeight.sort(function (a, b) { return b - a });
for (var j = 0; j < arrItems.length; j++) {
arrItems[j].style.height = arrHeight[0] + 'px';
}
top = menuItems[i].offsetTop;
arrHeight.length = arrItems.length = 0;
i = i - 1;
continue;
}
arrHeight[arrHeight.length] = menuItems[i].offsetHeight;
arrItems[arrItems.length] = menuItems[i];
}
arrHeight.sort(function (a, b) { return b - a });
for (var j = 0; j < arrItems.length; j++) {
arrItems[j].style.height = arrHeight[0] + 'px';
}
}
window.onresize = funcItemsHeight;
funcItemsHeight('.ВАШ_ЭЛЕМЕНТ');