Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 7th, 2020 138 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.      * Andrianov A.M.
  3.      * @param $xml
  4.      * @param $db
  5.      * @return string
  6.      * Продукты со значениями характеристик
  7.      */
  8.     static public function productsXML($xml, $db)
  9.     {
  10.         $productTable = Product::getTableSchema()->name;
  11.         $productValueTable = ProductValue::getTableSchema()->name;
  12.  
  13.         ini_set('memory_limit', '1000M');
  14.  
  15.  
  16. //        $db->createCommand("DELETE FROM $productTable")->execute();
  17. //        $db->createCommand("DELETE FROM $productValueTable")->execute();
  18.  
  19.         foreach($xml->PriceItem as $product){
  20.             if(!empty($product->Id)) {
  21.                 $n = $db->createCommand("INSERT INTO $productTable SET  code=:code,  `name`=:name, cost=:cost,
  22.                      cost_old=:cost_old,
  23.                      remainder_amount=:remainder_amount, category_id=:category_id,
  24.                      product_weight=:product_weight, parent_code=:parent_code, bonuses=:bonuses
  25.                      ON DUPLICATE KEY UPDATE `name`=:name , cost=:cost,  product_weight=:product_weight,
  26.                      cost_old=:cost_old, remainder_amount=:remainder_amount, parent_code=:parent_code ", [
  27.                     ':code' => $product->Id,
  28.                     ':name' => htmlspecialchars($product->Nametovar),
  29.                     ':cost' => $product->Cost,
  30.                     ':cost_old' => $product->CostOld ? $product->CostOld : 0,
  31.                     ':remainder_amount' => $product->Quantity,
  32.                     ':category_id' => $product->Group_Id,
  33.                     ':product_weight' => null,
  34.                     ':bonuses' => $product->Cost / Product::BONUSES_COST,
  35.                     ':parent_code' => empty($product->Parent_Id) ? null : $product->Parent_Id,
  36.                 ])->execute();
  37.                 //значения характеристик продукта
  38.                 $db->createCommand("DELETE FROM $productValueTable WHERE product_code='{$product->Id}'")->execute();
  39.  
  40.                 foreach ($product->Properties as $option){
  41.                     if(!empty($option->Value)) {
  42.                         $characteristics = CategoryCharacteristics::findOne(['option_id' => $option->Option_id]);
  43.                         $characteristicsName = $characteristics->name;
  44.                         $characteristicsMeasure = $characteristics->measure;
  45.  
  46.                         $db->createCommand("INSERT INTO $productValueTable SET  characteristics_id=:characteristics_id,
  47.                        value=:value, characteristics_name=:characteristics_name, product_code=:product_code,
  48.                        category_id=:category_id, characteristics_measure=:characteristics_measure
  49.                      ", [
  50.                             ':characteristics_id' => "$option->Option_id",
  51.                             ':value' => htmlspecialchars($option->Value),
  52.                             ':characteristics_name' => htmlspecialchars($characteristicsName),
  53.                             ':product_code' => "$product->Id",
  54.                             ':category_id' => "$product->Group_Id",
  55.                             ':characteristics_measure' => "$characteristicsMeasure",
  56.                         ])->execute();
  57.                     }
  58.                 }
  59.             }
  60.         }
  61.  
  62.         //связываем подчиненые продукты с главными
  63.         $products = Product::find()
  64.             ->innerJoinWith('parentProduct pr')
  65.             ->where(['not',['product.parent_code'=>null]])
  66.             ->all();
  67.  
  68.         foreach ($products as $product){
  69.             $parentId = $product->parentProduct->id;
  70.             $product->product_id =  $parentId;
  71.             $product->save(false);
  72.  
  73.             //$db->createCommand("UPDATE product SET product_id={$parentId} WHERE id='{$product->id}'")->execute();
  74.         }
  75.  
  76.         ini_set('memory_limit', '250M');
  77.         return 'Продукты и значения характеристик добавлены в базу данных';
  78.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top