не работает скипт. вместо создания типа basket ничего не происходи, сообщений про ошибку нет

Главные вкладки

Аватар пользователя riaron777 riaron777 10 сентября 2022 в 18:12

не работает скипт. вместо создания типа basket ничего не происходи, сообщений про ошибку нет

<?php

use Drupal\user\Entity\User;
use 
Drupal\node\Entity\Node;
use 
Symfony\Component\HttpFoundation\Request;
use 
Symfony\Component\DependencyInjection\ContainerInterface;
use 
Symfony\Component\HttpFoundation\RedirectResponse;
use \
Drupal\Core\Url ;
function 
generateCode($length 6)
{
$chars "abcdefghijklmnopqrstuvwxyzABCDEFGHI_JKLMNOPRQSTUVWXYZ0123456789";
$code "";
$clen strlen($chars) - 1;
while (
strlen($code) < $length) {
$code .= $chars[mt_rand(0$clen)];
}
return 
$code;
}

function 

shop_addtobasket() {
    
$user User::load(\Drupal::currentUser()->id());
    if(\
Drupal::entityTypeManager()->getStorage('node')->loadByProperties(['type' => 'basket','field_polzovatel'=>$user->getDisplayName()])!=null){
        
$a=\Drupal::entityTypeManager()->getStorage('node')->loadByProperties([    'type' => 'basket',    'field_polzovatel'=>$user->getDisplayName()]);
    
$count=count($a[array_key_first($a)]);
    }else{
        
$count=0;
    }
    if(
$count==or $count==0){
            if(
$count==0){
                if(
strlen($user->getDisplayName())>4){
                    
//$request= \Drupal::request()->query;
                    //$request=$request[array_key_first($request)];
                    
$article=\Drupal::request()->get('article');
                    
$b=\Drupal::entityTypeManager()->getStorage('node')->loadByProperties([
                    
'type' => 'product',
                    
'field_artikul'=>$article,
                    ]);
                    
$nodes=$b[array_key_first($b)];
                    
$tit=generateCode(10);
                    
$nod Node::create([
                    
// The node entity bundle.
                    
'type' => 'basket',
                    ]);
                    
$nod->set('title',$tit);
                    
$nod->set('uid',1);
                    
$nod->status=1;
                    
$nod->field_itogo=$nodes->field_cena;
                    
$nod->field_polzovatel=$user->getUsername();
                    
$nod->field_artikuly=$article;
                    
$nod->enforceIsNew;
                    
$nod->save();
            }
        return 
'hello basket empyty'.$article;
    }else{
                    
/**/
                    
if(count($a)==0){
                    
$article= \Drupal::request()->request->get('article');
                    
$a=\Drupal::entityTypeManager()->getStorage('node')->loadByProperties([
                        
'type' => 'basket',
                        
'field_artikuly'=>$article]);
                    
$values=$node->get('field_artikuly')->getValue();
                    
$values[]=$article;
                    
$b=\Drupal::entityTypeManager()->getStorage('node')->loadByProperties([
                    
'type' => 'product',
                    
'field_artikul'=>$article
                    
]);
                    
$nod=$b[array_key_first($b)];
                    
$node->set('field_artikuly'$values);
                    foreach(
$node->get('field_artikuly')  as $nodes){
                            
$b=\Drupal::entityTypeManager()->getStorage('node')->loadByProperties([
                            
'type' => 'product',
                            
'field_artikul'=>$nodes->value
                            
]);
                            
$nid=current($b);
                            
$tt+=$nid->get('field_cena')[0]->value;
                    }
                    
$node->set('field_itogo'$tot);
                    
$node->save();
                    }elseif(
count($a)<or count($a)>=1){
                            return 
'hello';
                    }
            }
    }elseif(
$count<or $count>=2){
        
$storage = \Drupal::entityTypeManager()->getStorage('node');
        
$query $storage->getQuery();
        
$query->condition('uid'1);
        
$query->condition('type''basket');
        
$query->condition('field_polzovatel'$user->getUsername());
        
$ids $query->execute();

        if (!empty(
            

$ids)) {
            
$entities $storage->loadMultiple($ids);
            
$storage->delete($entities);
        }
    }
    
    
    

  }

  function 

shop_basket() { 
    
$user User::load(\Drupal::currentUser()->id());
    
$a=\Drupal::entityTypeManager()->getStorage('node')->loadByProperties([
        
'type' => 'basket',
        
'field_polzovatel'=>$user->getDisplayName(),
        ]);
        
$node=reset($a);
        
$count=count($a);
        
        if(
$count==0){
            
$outp='Корзина пуста';
        }elseif(
$count==1){
            foreach(
$node->get('field_artikuly')  as $nodes){
            
$a=\Drupal::entityTypeManager()->getStorage('node')->loadByProperties([
                    
'type' => 'product',
                    
'field_articul'=>$nodes->value,
                    ]);
                
$nid=reset($a);
                
$ww.="
                <tr>
                <td>"
$nodes->value."</td>
                <td>"
.$nid->get('field_name')[0]->value."</td>
                <td>"
.$nid->get('field_cena')[0]->value."</td>
                <td><a href='dfbasket?article="
.$nodes->value."'>Удалить</a></td>
                </tr>"
;
                
$tt+=$nid->get('field_cena')[0]->value;
            }
            
$b="<table>
            <tr>
                <td><p>Артикул</p></td>
                <td><p>Нвзвание Товара</p></td>
                <td><p>Цена</p></td>
                <td></td>
                <td><p>Итого</p></td>
            </tr>"
;
            
$c="<tr>
                <td></td>    
                <td></td>    
                <td></td>    
                <td></td>    
                <td>"
.$tt."</td>    
            </tr>
            </table>
            <a href='atorders'>Заказать</a>
            "
;
        
$outp=$b.$ww.$c;
    

  }elseif(

$count>1){
                  
$outp='Произошла ошибка свяжитесь с администрацией';

  }
        return 

$outp;

  }}

?>