Jump to content
khvoroffski

Вывод в карточку товара кнопки редактировать и SKU как ссылка

Recommended Posts

Добрый день!

Моя цель вывести в карточке товара кнопку "Редактировать товар" - что уже сделал и кнопку-ссылку SKU (так как sku у меня это ссылки на товары на сайтах поставщиков), я собрал вот такую конструкцию

Спойлер

<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>Edit product button for product for Tech store</name>
	<code>edit-button-fron-end</code>
	<version>1.0</version>
	<author>Alexander Khvorov</author>
	<link>https://baconagency.ru</link>

	<file path="catalog/language/en-gb/product/product.php">
		<operation>
			<search><![CDATA[$_['error_rating']             = 'Warning: Please select a review rating!';]]></search>
			<add position="after">
				<![CDATA[// Edit product button
		$_['text_button_edit'] = 'Edit Product';
				]]>
				<![CDATA[// Product link
		$_['product_vendor_link'] = 'Vendor link';
				]]>
			</add>
		</operation>
	</file>
		<file path="catalog/language/ru-ru/product/product.php">
		<operation>
			<search><![CDATA[$_['error_rating']                            = 'Пожалуйста поставьте оценку!';]]></search>
			<add position="after">
				<![CDATA[// Edit product button
		$_['text_button_edit'] = 'Редактировать товар';
				]]>
								<![CDATA[// Product link
		$_['product_vendor_link'] = 'Ссылка на товар у поставщика';
				]]>
			</add>
		</operation>
	</file>

	<file path="catalog/controller/product/product.php">
		<operation>
			<search><![CDATA[$product_info = $this->model_catalog_product->getProduct($product_id);]]></search>
			<add position="after">
				<![CDATA[
				$data['button_edit_product'] = $this->language->get('text_button_edit');
				$data['product_vendor_link'] = $this->language->get('product_vendor_link');

				]]>
			</add>
		</operation>
				<operation>
			<search><![CDATA[$data['model'] = $product_info['model'];]]></search>
			<add position="after">
				<![CDATA[
				$data['sku'] = $product_info['sku'];
				]]>
			</add>
		</operation>
		<operation>
        	<search><![CDATA[if ($product_info) {]]></search>
        	<add position="after">
        		<![CDATA[
					if(!empty($this->session->data['user_id']) && !empty($this->session->data['token'])){
						$data['edit_product'] = '<a href="'.$this->url->linkEditProduct('catalog/product/edit', 'token=' . $this->session->data['token'].'&product_id='.$product_id, 'true').'" target="_blank" class="btn btn-warning btn-lg btn-block">'.$data['button_edit_product'].'</a>';
						$data['vendor_link'] = '<a href="" target="_blank" class="btn btn-warning btn-lg btn-block">'.$data['product_vendor_link'].'</a>';
					}

         		]]>
     		</add>
      	</operation>
   </file>

   <file path="system/library/url.php">
		<operation>
        	<search><![CDATA[public function link($route, $args = '', $secure = false) {]]></search>
         	<add position="before">
         	<![CDATA[public function linkEditProduct($route, $args = '', $secure = false) {
		if ($this->ssl && $secure) {
			$url = $this->ssl . 'admin/index.php?route=' . $route;
		} else {
			$url = $this->url . 'admin/index.php?route=' . $route;
		}

		if ($args) {
			if (is_array($args)) {
				$url .= '&amp;' . http_build_query($args);
			} else {
				$url .= str_replace('&', '&amp;', '&' . ltrim($args, '&'));
			}

						return $url;
					}
		}
         		]]>
         	</add>
		</operation>
	</file>

	<file path="catalog/view/theme/oct_techstore/template/product/product.tpl">
		<operation>
        	<search><![CDATA[<?php if ($disable_buy == 0) { ?>]]></search>
        	<add position="before" offset="1">
        	<![CDATA[<?php if(!empty($edit_product)){echo $edit_product; } ?>]]>
        	<![CDATA[<?php if(!empty($vendor_link)){echo $vendor_link; } ?>]]>
        	</add>
		</operation>
	</file>
</modification>

 

И единственное что не могу доделать - это ссылку вот в этом участке  - $data['vendor_link'] = '<a href="" target="_blank" class="btn btn-warning btn-lg btn-block">'.$data['product_vendor_link'].'</a>';

 

Уже перебрал море вариантов и раз 50 положил сайт )))

 

Помогите пожалуйста дописать кусочек.

Share this post


Link to post
Share on other sites
$data['vendor_link'] = '<a href="" target="_blank" class="btn btn-warning btn-lg btn-block">'.$data['product_vendor_link'].'</a>';

 

$data['vendor_link'] = '<a href="'.$data['product_vendor_link'].'" target="_blank" class="btn btn-warning btn-lg btn-block"></a>';

Share this post


Link to post
Share on other sites
13 минут назад, AlexDW сказал:

$data['vendor_link'] = '<a href="" target="_blank" class="btn btn-warning btn-lg btn-block">'.$data['product_vendor_link'].'</a>';

 


$data['vendor_link'] = '<a href="'.$data['product_vendor_link'].'" target="_blank" class="btn btn-warning btn-lg btn-block"></a>';

Такая конструкция просто поместит  текст "Ссылка на товар у поставщика", а мне нужно разместить туда sku, то есть что-то вроде -

$data['vendor_link'] = '<a href="'.$data['sku'].'" target="_blank" class="btn btn-warning btn-lg btn-block">'.$data['product_vendor_link'].'</a>';

но такая конструкция вызывает undefined index

Edited by khvoroffski

Share this post


Link to post
Share on other sites

так сделайте по-человечески - вывод в шаблоне, а через контроллер саму ссылку

Share this post


Link to post
Share on other sites
4 минуты назад, AlexDW сказал:

так сделайте по-человечески - вывод в шаблоне, а через контроллер саму ссылку

А не понимаю как в шаблоне выводить только админу, так бы сделал просто через if admin (условно)

 

В шаблоне выводится вот так: 

<li class="product-info-li main-product-sku"><span><?php echo $text_sku; ?></span> <?php if ($oct_advanced_options_settings_data['allow_sku']) { ?><strong id="main-product-sku" style="font-weight: normal;" <?php if ($tech_pr_micro == "on") { ?> itemprop="sku"<?php } ?>><?php echo $sku; ?></strong><?php } else { ?><?php echo $sku; ?><?php } ?></li>

Я скрыл вывод вот так

	<file path="catalog/view/theme/oct_techstore/template/product/product.tpl">
		<operation>
                <search position="replace">
                <![CDATA[<li class="product-info-li main-product-sku"><span><?php echo $text_sku; ?></span> <?php if ($oct_advanced_options_settings_data['allow_sku']) { ?><strong id="main-product-sku" style="font-weight: normal;" <?php if ($tech_pr_micro == "on") { ?> itemprop="sku"<?php } ?>><?php echo $sku; ?></strong><?php } else { ?><?php echo $sku; ?><?php } ?></li>]]>
             </search>
                <add>
                <![CDATA[]]>
             </add>
            </operation>
	</file>

наверное можно как-то просто обернуть в if(....и скрывать от посетителей, но как я не знаю(т.к. с опенкартом плохо знаком), поэтому и выдумываю схемы ))

Share this post


Link to post
Share on other sites

Сделал:

Спойлер

<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>Edit product button for product for Tech store</name>
	<code>edit-button-fron-end</code>
	<version>1.0</version>
	<author>Alexander Khvorov</author>
	<link>https://baconagency.ru</link>

	<file path="catalog/language/en-gb/product/product.php">
		<operation>
			<search><![CDATA[$_['error_rating']             = 'Warning: Please select a review rating!';]]></search>
			<add position="after">
				<![CDATA[// Edit product button
		$_['text_button_edit'] = 'Edit Product';
				]]>
				<![CDATA[// Product link
		$_['product_vendor_link'] = 'Vendor link';
				]]>
			</add>
		</operation>
	</file>
		<file path="catalog/language/ru-ru/product/product.php">
		<operation>
			<search><![CDATA[$_['error_rating']                            = 'Пожалуйста поставьте оценку!';]]></search>
			<add position="after">
				<![CDATA[// Edit product button
		$_['text_button_edit'] = 'Редактировать товар';
				]]>
								<![CDATA[// Product link
		$_['product_vendor_link'] = 'Ссылка на товар у поставщика';
				]]>
			</add>
		</operation>
	</file>

	<file path="catalog/controller/product/product.php">
		<operation>
			<search><![CDATA[$product_info = $this->model_catalog_product->getProduct($product_id);]]></search>
			<add position="after">
				<![CDATA[
				$data['button_edit_product'] = $this->language->get('text_button_edit');
				$data['product_vendor_link'] = $this->language->get('product_vendor_link');

				]]>
			</add>
		</operation>
				<operation>
			<search><![CDATA[$data['model'] = $product_info['model'];]]></search>
			<add position="after">
				<![CDATA[
				$data['sku'] = $product_info['sku'];
				]]>
			</add>
		</operation>
				<operation>
        	<search><![CDATA[$data['points'] = $product_info['points'];]]></search>
        	<add position="after">
        		<![CDATA[
					if(!empty($this->session->data['user_id']) && !empty($this->session->data['token'])){
				$data['vendor_link'] = '<a href="'.$data['sku'].'" target="_blank" class="btn btn-warning btn-lg btn-block">'.$data['product_vendor_link'].'</a>';
					}

         		]]>
     		</add>
      	</operation>
		<operation>
        	<search><![CDATA[if ($product_info) {]]></search>
        	<add position="after">
        		<![CDATA[
					if(!empty($this->session->data['user_id']) && !empty($this->session->data['token'])){
						$data['edit_product'] = '<a href="'.$this->url->linkEditProduct('catalog/product/edit', 'token=' . $this->session->data['token'].'&product_id='.$product_id, 'true').'" target="_blank" class="btn btn-warning btn-lg btn-block">'.$data['button_edit_product'].'</a>';
					}

         		]]>
     		</add>
      	</operation>
   </file>

   <file path="system/library/url.php">
		<operation>
        	<search><![CDATA[public function link($route, $args = '', $secure = false) {]]></search>
         	<add position="before">
         	<![CDATA[public function linkEditProduct($route, $args = '', $secure = false) {
		if ($this->ssl && $secure) {
			$url = $this->ssl . 'admin/index.php?route=' . $route;
		} else {
			$url = $this->url . 'admin/index.php?route=' . $route;
		}

		if ($args) {
			if (is_array($args)) {
				$url .= '&amp;' . http_build_query($args);
			} else {
				$url .= str_replace('&', '&amp;', '&' . ltrim($args, '&'));
			}

						return $url;
					}
		}
         		]]>
         	</add>
		</operation>
	</file>

	<file path="catalog/view/theme/oct_techstore/template/product/product.tpl">
		<operation>
        	<search><![CDATA[<?php if ($disable_buy == 0) { ?>]]></search>
        	<add position="before" offset="1">
        	<![CDATA[<?php if(!empty($edit_product)){echo $edit_product; } ?>]]>
        	<![CDATA[<?php if(!empty($vendor_link)){echo $vendor_link; } ?>]]>
        	</add>
		</operation>
	</file>
</modification>

 

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.