Загрузка товара в инстаграм
После того как вы отредактировали товар и нажали сохранить или добавили новый, он автоматически будет загружен в instagram.
Для начала добавим галку в редактирование товара, для добавление в инстаграм
\administrator\components\com_virtuemart\views\product\tmpl\product_edit_information.php
найдите
<label><?php echo VmHTML::checkbox('published', $this->product->published); ?><?php echo vmText::_('COM_VIRTUEMART_PUBLISHED') ?></label>
чуть ниже добавьте
<label><input type="hidden" name="instagram" value="0"><input type="checkbox" name="instagram" value="1" checked="checked">Обновить дату и добавить в инстаграм</label>
Добавляем сам код отправки:
\administrator\components\com_virtuemart\models\product.php
Находим
// Process the images $mediaModel = VmModel::getModel ('Media'); $mediaModel->storeMedia ($data, 'product'); }
Ниже добавляем
if( $data['instagram'] AND $data['published'] ) { //получаем название категории $db = JFactory::getDbo(); $db->setQuery("SELECT cruru.category_name FROM #__virtuemart_product_categories pc LEFT JOIN #__virtuemart_categories_ru_ru cruru ON (cruru.virtuemart_category_id=pc.virtuemart_category_id) WHERE virtuemart_product_id = '".$data['virtuemart_product_id']."' ORDER BY pc.virtuemart_category_id DESC LIMIT 0,1"); $namecat = $db->loadResult(); $namecat = str_replace( ",", " ", $namecat ); $namecat = preg_replace( "#\b([а-яёa-z]{3,}+)\s?#ui", "#$1 ", $namecat ); //состовляем теги из названия $name_teg = preg_replace( "#\b([а-яёa-z]{3,}+)\s?#ui", "#$1 ", $data['product_name'] ); //состовляем $tags = $name_teg . ' ' . $namecat; //array_unique без учета регистра utf-8 function strtolower_utf8($a){ return mb_strtolower($a,'UTF-8'); } function array_iunique($array) { return array_intersect_key( $array, array_unique(array_map("strtolower_utf8",$array)) ); } //удаляем одинаковые теги $massiv = explode(" ", $tags); // из строки делаем массив $massiv = array_iunique($massiv); //удаляем дубляжи $tags = implode(" ", $massiv); //возвращаем в строку $link_uncode = 'https://АДРЕС ВАШЕГО САЙТА/?option=com_virtuemart&view=productdetails&virtuemart_category_id='.$catid.'&virtuemart_product_id='.$data['virtuemart_product_id']; //состовляем комментарий $comment = mb_substr(htmlspecialchars ( strip_tags ( stripslashes ( trim ($data['product_desc']) ) ) ), 0, 1200, 'UTF-8') . ', Артикул: ' . $data['product_sku'] . ', Ссылка: ' . $link_uncode . ', ' . $tags .' #лучшаякомпания'; //получаем ссылку на изображение $db = JFactory::getDbo(); $db->setQuery("SELECT m.file_url FROM #__virtuemart_product_medias pm LEFT JOIN #__virtuemart_medias m ON (m.virtuemart_media_id=pm.virtuemart_media_id) WHERE pm.virtuemart_product_id='".$data['virtuemart_product_id']."' AND pm.ordering='1'"); $file_url = $db->loadResult(); //получаем название файла preg_match( "#[^/]+$#is", $file_url, $file_name ); $file_url = $file_name[0]; //корень каталога define( 'ROOT_DIR', substr( dirname( __FILE__ ), 0, -47 ) ); //подключаем классы include 'simpleimage.class.php'; include 'instagram.class.php'; //нужно вписать только логин и пароль $username = 'логин'; // your username $password = 'пароль'; // your password $emailerror = ''; //ваша почта для отправки ошибок $filename = $file_url; // your sample photo $caption = $comment; // your caption $product_image = ROOT_DIR . '/images/stories/virtuemart/product/' . $filename; $square = ROOT_DIR . '/cache/' . $filename; $image = new SimpleImage(); $image->load($product_image); $image->resize(600,600); $image->save($square, IMAGETYPE_JPEG); unset($image); $insta = new instagram(); $response = $insta->Login($username, $password); if(strpos($response[1], "Sorry")) { //echo "Request failed, there's a chance that this proxy/ip is blocked"; //print_r($response); //exit(); mail($emailerror, 'Request failed, there\'s a chance that this proxy/ip is blocked', $response, 'Content-type: text/html; charset=utf-8'); } if(empty($response[1])) { //echo "Empty response received from the server while trying to login"; //print_r($response); //exit(); mail($emailerror, 'Empty response received from the server while trying to login', $response, 'Content-type: text/html; charset=utf-8'); } $insta->Post($square, $caption); //удаляем изображение для инстаграм unlink(ROOT_DIR . '/cache/' . $filename); }
В папку \administrator\components\com_virtuemart\models\ загружаем файлы simpleimage.class.php и instagram.class.php
Скачать “instagram.zip” ver 1 Скачано 227 раз – 2 КБ – md5 f8627c386db90e1236f5745e268383dd
Ден
24.11.2018это модуль для какого двига?
Ден
24.11.2018все нашел)