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>
Could anyone offer advice?
Thanks & best,
Torge