本文整理汇总了PHP中app\models\Product::getProductFromExportToSite方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::getProductFromExportToSite方法的具体用法?PHP Product::getProductFromExportToSite怎么用?PHP Product::getProductFromExportToSite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Product
的用法示例。
在下文中一共展示了Product::getProductFromExportToSite方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request, History $historyModel, Cloud $cloudModel, Product $productModel, Purchase $purchaseModel)
{
if (isset($_POST['delete_all_flags'])) {
if (!right('Import')) {
abort(404);
}
$productModel->deleteAllFlags();
Session::flash('message', GetMessages("SUCCESS_DELETE_FLAGS"));
return redirect()->route('cloud.index');
}
if (isset($_POST['delete_all_export_list'])) {
if (!right('Import')) {
abort(404);
}
$productModel->deleteAllExport();
Session::flash('message', GetMessages("SUCCESS_DELETE_FLAGS"));
return redirect()->route('cloud.index');
}
if (isset($_POST['ajax'])) {
if (!right('Import')) {
abort(404);
}
Session::forget('idsNewProducts');
}
if (isset($_POST['export_site'])) {
if (!right('Import')) {
abort(404);
}
//pr($_POST);
if (isset($_POST['field'])) {
$products = $productModel->getProductFromExportToSite();
if (count($products) > 0) {
$res = array();
$res[0][] = iconv('UTF-8', 'cp1251//TRANSLIT', 'ВП ID');
$res[0][] = iconv('UTF-8', 'cp1251//TRANSLIT', 'Производитель');
$res[0][] = iconv('UTF-8', 'cp1251//TRANSLIT', 'Наменование');
if (isset($_POST['field']['GK'])) {
$res[0][] = iconv('UTF-8', 'cp1251//TRANSLIT', 'ID ГК');
$res[0][] = iconv('UTF-8', 'cp1251//TRANSLIT', 'Цена ГК');
$res[0][] = iconv('UTF-8', 'cp1251//TRANSLIT', 'Валюта ГК');
$res[0][] = iconv('UTF-8', 'cp1251//TRANSLIT', 'Активность ГК');
$res[0][] = iconv('UTF-8', 'cp1251//TRANSLIT', 'Яндекс ГК');
}
if (isset($_POST['field']['TV'])) {
$res[0][] = iconv('UTF-8', 'cp1251//TRANSLIT', 'ID ТВ');
$res[0][] = iconv('UTF-8', 'cp1251//TRANSLIT', 'Цена ТВ');
$res[0][] = iconv('UTF-8', 'cp1251//TRANSLIT', 'Валюта ТВ');
$res[0][] = iconv('UTF-8', 'cp1251//TRANSLIT', 'Активность ТВ');
$res[0][] = iconv('UTF-8', 'cp1251//TRANSLIT', 'Яндекс ТВ');
}
if (isset($_POST['field']['MK'])) {
$res[0][] = iconv('UTF-8', 'cp1251//TRANSLIT', 'ID МК');
$res[0][] = iconv('UTF-8', 'cp1251//TRANSLIT', 'Цена МК');
$res[0][] = iconv('UTF-8', 'cp1251//TRANSLIT', 'Валюта МК');
$res[0][] = iconv('UTF-8', 'cp1251//TRANSLIT', 'Активность МК');
$res[0][] = iconv('UTF-8', 'cp1251//TRANSLIT', 'Яндекс МК');
}
$res[0][] = iconv('UTF-8', 'cp1251//TRANSLIT', 'Наличие');
$i = 1;
foreach ($products as $product) {
$res[$i][] = $product->id;
$res[$i][] = iconv('UTF-8', 'cp1251//TRANSLIT', $product->brand);
$res[$i][] = iconv('UTF-8', 'cp1251//TRANSLIT', $product->name);
if (isset($_POST['field']['GK'])) {
if (strpos($product->GK_price, '.')) {
$product->GK_price = str_replace('.', ',', $product->GK_price);
//заменяем точку на запятую, ибо эксель ебанутый((
}
if ($product->GK_currency == 'RUB') {
$product->GK_price = intval($product->GK_price);
//округляем, если валюта RUB
}
$res[$i][] = $product->GK_id;
$res[$i][] = $product->GK_price;
$res[$i][] = $product->GK_currency;
$res[$i][] = $product->GK_enabled;
$res[$i][] = $product->GK_yandex_enabled;
}
if (isset($_POST['field']['TV'])) {
if (strpos($product->TV_price, '.')) {
$product->TV_price = str_replace('.', ',', $product->TV_price);
//заменяем точку на запятую, ибо эксель ебанутый((
}
if ($product->TV_currency == 'RUB') {
$product->TV_price = intval($product->TV_price);
//округляем, если валюта RUB
}
$res[$i][] = $product->TV_id;
$res[$i][] = $product->TV_price;
$res[$i][] = $product->TV_currency;
$res[$i][] = $product->TV_enabled;
$res[$i][] = $product->TV_yandex_enabled;
}
if (isset($_POST['field']['MK'])) {
//.........这里部分代码省略.........
示例2: send
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function send($site_id)
{
$productModel = new Product();
$toExport = $productModel->getProductFromExportToSite();
if (!empty($toExport)) {
switch ($site_id) {
case 'GK':
$connect_GK = $this->connect($site_id);
$currentCurrency = $connect_GK->table('shop_currency')->select('code', 'rate')->get();
//придется получить курсы с сайта, увы :(
$_rates = array();
foreach ($currentCurrency as $curr) {
$_rates[$curr->code] = $curr->rate;
}
try {
foreach ($toExport as $product) {
if (!empty($product->GK_id)) {
/*Modificated*/
$product->in_stock == 1 ? $product->GK_in_stock = 999 : ($product->GK_in_stock = -999);
$product->GK_yandex_enabled == 1 ? $product->GK_yandex_enabled = 3 : ($product->GK_yandex_enabled = 2);
if ($product->GK_currency == 'RUB') {
$product->GK_price = intval($product->GK_price);
$product->GK_rub_price = intval($product->GK_price);
} else {
$product->GK_rub_price = $product->GK_price * $_rates[$product->GK_currency];
}
/*Query*/
$connect_GK->table('shop_product as sp')->join('shop_product_skus as sps', 'sp.id', '=', 'sps.product_id')->where('sps.sku', $product->GK_id)->update(array('sp.status' => $product->GK_enabled, 'sp.count' => $product->GK_in_stock, 'sps.count' => $product->GK_in_stock, 'sp.type_id' => $product->GK_yandex_enabled, 'sp.price' => $product->GK_rub_price, 'sp.min_price' => $product->GK_rub_price, 'sp.max_price' => $product->GK_rub_price, 'sps.price' => $product->GK_price, 'sps.primary_price' => $product->GK_rub_price, 'sp.currency' => $product->GK_currency));
}
}
} catch (\Exception $e) {
echo "ERROR {$site_id}";
$this->disconnect($site_id);
exit;
}
break;
case 'TV':
$connect_TV = $this->connect($site_id);
$currentCurrency = $connect_TV->table('diafan_shop_currency')->select('id', 'name', 'exchange_rate')->get();
$_rates = array();
foreach ($currentCurrency as $curr) {
$_rates[$curr->name] = array('id' => $curr->id, 'rate' => $curr->exchange_rate);
}
try {
foreach ($toExport as $product) {
if (!empty($product->TV_id)) {
/*Modificated*/
$product->TV_in_stock = $product->in_stock == 1 ? 100 : 0;
/*Query*/
$connect_TV->table('diafan_shop')->where('id', $product->TV_id)->update(array('act1' => $product->TV_enabled, 'show_yandex' => $product->TV_yandex_enabled));
$currentPrices = $connect_TV->table('diafan_shop_price')->where('good_id', $product->TV_id)->get();
if (!isset($currentPrices[0])) {
$currentPrices[0] = new Collection();
$currentPrices[0]->old_price = '';
$currentPrices[0]->date_start = '';
$currentPrices[0]->date_finish = '';
$currentPrices[0]->discount = '';
$currentPrices[0]->discount_id = '';
$currentPrices[0]->person = '';
$currentPrices[0]->role_id = '';
$currentPrices[0]->import_id = '';
$currentPrices[0]->trash = '';
}
$connect_TV->table('diafan_shop_price')->where('good_id', $product->TV_id)->delete();
$priceId = $connect_TV->table('diafan_shop_price')->insertGetId(array('good_id' => $product->TV_id, 'price' => $product->TV_price, 'old_price' => $currentPrices[0]->old_price, 'count_goods' => $product->TV_in_stock, 'price_id' => 0, 'date_start' => $currentPrices[0]->date_start, 'date_finish' => $currentPrices[0]->date_finish, 'discount' => $currentPrices[0]->discount, 'discount_id' => $currentPrices[0]->discount_id, 'person' => $currentPrices[0]->person, 'role_id' => $currentPrices[0]->role_id, 'currency_id' => $product->TV_currency == 'RUB' ? 0 : $_rates[$product->TV_currency]['id'], 'import_id' => $currentPrices[0]->import_id, 'trash' => $currentPrices[0]->trash));
if ($product->TV_currency != 'RUB') {
$priceId = $connect_TV->table('diafan_shop_price')->insertGetId(array('good_id' => $product->TV_id, 'price' => $product->TV_price * $_rates[$product->TV_currency]['rate'], 'old_price' => $currentPrices[0]->old_price, 'count_goods' => $product->TV_in_stock, 'price_id' => 0, 'date_start' => $currentPrices[0]->date_start, 'date_finish' => $currentPrices[0]->date_finish, 'discount' => $currentPrices[0]->discount, 'discount_id' => $currentPrices[0]->discount_id, 'person' => $currentPrices[0]->person, 'role_id' => $currentPrices[0]->role_id, 'currency_id' => 0, 'import_id' => $currentPrices[0]->import_id, 'trash' => $currentPrices[0]->trash));
}
$connect_TV->table('diafan_shop_price')->where('good_id', $product->TV_id)->update(array('price_id' => $priceId));
}
}
} catch (\Exception $e) {
echo "ERROR {$site_id}";
$this->disconnect($site_id);
var_dump($e->getMessage());
var_dump($e->getLine());
exit;
}
break;
// case 'TV':
// $connect_TV = $this->connect($site_id);
//
// $currentCurrency = $connect_TV->table('currency')->select('id', 'system_name')->get(); //придется получить курсы с сайта, увы :(
//
// $_rates = array();
// foreach($currentCurrency as $curr){
// $_rates[$curr->system_name] = $curr->id;
// }
//
// try {
// foreach($toExport as $product) {
// if (!empty($product->TV_id)) {
//
// /*Modificated*/
// $product->TV_enabled == 1 ? $product->TV_enabled = 'yes' : $product->TV_enabled = 0;
//.........这里部分代码省略.........