Post by xoomit » Wed Jun 15, 2016 12:57 pm

Hej guys,

I am trying to build a vqmod that adds a button on the product page next to or below the add to basket button. The button should say "Buy at Amazon" and deeplink into the respective Amazon product page. Unfortunately I am not a coder, I have some knowledge of html/css but very little php knowledge so I couldn't get this to work.

I created a table in my DB called "amazon_checkout". It includes the fields "product_id" and "amazon_landing_url" and I have the URLs in there for all my products. So really what the vqmod needs to do is look up the correct product id when I am on a product page and set the href on the button accordingly.

Here is what I did:

Code: Select all

<modification>

	<id>Add Amazon checkout button</id>
	<version>1.0</version>
	<vqmver>2.5.0</vqmver>	

<file name="admin/model/catalog/product.php">
	<operation>
			<search position="after"><![CDATA[
			$product_id = $this->db->getLastId();
			]]></search>
			<add><![CDATA[
			//echo "<pre>"; print_r($data);
			$q3 = "INSERT INTO " . DB_PREFIX . "amazon_checkout SET product_id = '" . $product_id . "', landing_url = '" . $this->db->escape($data['amazon_landing_url']) . "'";
			$this->db->query($q3);
                    
			]]></add>
	</operation>
	
	<operation>
			<search position="after"><![CDATA[
			$this->db->query("DELETE FROM " . DB_PREFIX . "product_description WHERE product_id = '" . (int)$product_id . "'");
			]]></search>
			<add><![CDATA[
			//print_r($data);die;
			$query = $this->db->query("SELECT *  FROM " . DB_PREFIX . "amazon_checkout  WHERE product_id = '" . (int)$product_id . "'");
			
			if ($query->num_rows) {
			$q4 = "UPDATE " . DB_PREFIX . "amazon_checkout SET landing_url = '" . $this->db->escape($data['amazon_landing_url']) .  "' WHERE product_id = '" . (int)$product_id . "'";
			$this->db->query($q4);
			}
			else{
			$this->db->query("INSERT INTO " . DB_PREFIX . "amazon_checkout SET product_id = '" . $product_id . "', landing_url = '" . $this->db->escape($data['amazon_landing_url']) . "'");
                    
			}
                    
			]]></add>
	</operation>
</file>

<file name="catalog/controller/product/product.php">	
	<operation>
			<search position="before"><![CDATA[
			$data['discounts'] = array();
			]]></search>
			<add><![CDATA[
			$this->load->model('module/amazon_upsell');
			$amazon_checkout = $this->model_module_amazon_upsell->getAmazonUrl($this->request->get['product_id']);
			//print_r($amazon_upsell);
			if(empty($amazon_upsell))
			{
				$data['landeseite'] = '';
			}else{
				$data['landeseite'] = $amazon_upsell[0]['landing_url'];
			}
			]]></add>
	</operation>
</file>

<file name="catalog/view/theme/pavilion/template/product/product.tpl">
	<operation>
			<search position="before"><![CDATA[
			<?php if ($minimum > 1): ?>
			]]></search>
			<add><![CDATA[
			<?php if($landeseite != ''){ ?>
			<br/><b><?php echo $landeseite;?> Test</b>.
			<?php } ?>
			]]></add>
	</operation>
</file>

</modification>
Unfortunately I get an error saying "Notice: Error: Could not load model /home/cbruxido/oc2/catalog/model/module/amazon_checkout.php! in /home/cbruxido/oc2/vqmod/vqcache/vq2-system_modification_system_engine_loader.php on line 24".

Could anyone offer advice?

Thanks & best,
Torge

New member

Posts

Joined
Tue Jun 19, 2012 6:09 am

Post by xoomit » Fri Jun 17, 2016 12:42 am

Ok, I guess I got a bit closer to the solution.

I now have the following code as vqmod:

Code: Select all

<modification>

	<id>Add Amazon checkout button</id>
	<version>1.0</version>
	<vqmver>2.5.0</vqmver>
	<author>Torge Kahl</author>
	
<file name="catalog/controller/product/product.php">
	
	<operation>
			<search position="before"><![CDATA[
			$data['discounts'] = array();
			]]></search>
			<add><![CDATA[
			$this->load->model('module/amazon_upsell');
			$customshippingdata = $this->model_module_Amazonbasket->getAmazonUrl($this->request->get['product_id']);
			//print_r($landung_url);
			if(empty($landung_url))
			{
				$data['landeseite'] = '';
			}else{
				$data['landeseite'] = $customshippingdata[0]['amazon_landing_url'];
			}
			]]></add>
	</operation>
</file>

<file name="catalog/view/theme/pavilion/template/product/product.tpl">
	
	<operation>
			<search position="before"><![CDATA[
			<?php if ($minimum > 1): ?>
			]]></search>
			<add><![CDATA[
			<?php if($landeseite != ''){ ?>
			<div class="buy-at-amazon">
				<br/><b><?php echo $landeseite?>. Bitte beachte</b>.
			</div>
			<div style="clear:both;"></div>
			<?php } ?>
			]]></add>
	</operation>
</file>

</modification>
And the following code at catalog/model/module/amazon_upsell.php

Code: Select all

<?php 
class ModelModuleAmazonbasket extends Model {
	public function getAmazonUrl($product_id) {
		$q = "SELECT * FROM " . DB_PREFIX . "amazon_checkout where product_id = '".$product_id."' and amazon_landing_url != ''";
		$query = $this->db->query($q);
		//print_r($query->rows);die;
		return $query->rows;
	}
}
?>
Unfortunately, I get a blank page when uploading the vqmod xml. Anyone has any idea why?

Thanks & best,
Torge

New member

Posts

Joined
Tue Jun 19, 2012 6:09 am
Who is online

Users browsing this forum: No registered users and 68 guests