2 Replies - 201 Views - Last Post: 12 December 2018 - 08:24 AM Rate Topic: -----

#1 Mattster   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-December 18

php and mysql query for Opencart.

Posted 12 December 2018 - 06:07 AM

We have an Opencart extension that applies a shipping rate to certain postcodes. The only problem is when the postcode matches, the website user is offered the free shipping as an option AS WELL as the postcode applied rate.
So the user has the option to pay 30.00 shipping or free shipping (the free shipping stays active regardless). My idea was to have a value on the database that is changed by the postcode shipping module when a postcode matches. Then the free shipping module queries the database to check, then if postcode shipping is required the free shipping is disabled.

All of this is in a vqmod xml file. The error message is just 'internal server error'.
I'm thinking the syntax on the query is wrong, or is the entire idea flawed?

This query works fine in the phpmyadmin page no problem.
UPDATE oc_postcode_set SET postcodestatus = 'TRUE';

<modification>         
    	<id>Remove Free shipping, when Postcode Shipping OC 2.3.0.2</id>         
        <version>1.0.0.0</version>         
        <vqmver>2.5.1</vqmver>         
        <author></author> 
    <file name="catalog/model/extension/shipping/***filename***.php">
        <operation>
          <search position="before">
            <![CDATA[
                foreach ($rates as $rate) {
             ]]>
          </search>
          <add>
            <![CDATA[
                $this->db->query("UPDATE `" . DB_PREFIX . "`.`oc_postcode_set` SET `postcodestatus` = 'FALSE'");
             ]]>
          </add>
          <search position="before">
            <![CDATA[
                break;
             ]]>
          </search>
          <add>
            <![CDATA[
                $this->db->query("UPDATE `" . DB_PREFIX . "`.`oc_postcode_set` SET `postcodestatus` = 'TRUE'");
             ]]>
          </add>
        </operation>
    <file name="catalog/model/extension/shipping/free.php">
        <operation>
          <search position="before">
            <![CDATA[
                $method_data = array();
             ]]>
          </search>
          <add>
            <![CDATA[
                $sql = $this->db->query("SELECT 'postcodestatus' FROM `" . DB_PREFIX . "oc_postcode_set`");
                if ($sql->row['postcodestatus']) == 'TRUE' {
                $status = false;
                }
             ]]>
          </add>
        </operation>
      </file>
    </modification>


Is This A Good Question/Topic? 0
  • +

Replies To: php and mysql query for Opencart.

#2 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2760
  • View blog
  • Posts: 10,946
  • Joined: 03-December 12

Re: php and mysql query for Opencart.

Posted 12 December 2018 - 08:20 AM

I'm going on the belief that there is more than one record in that table? Which means the database is saving you from yourself... That query would update the entire table, not just one, and I don't know a single person that has not screwed a table by leaving off the where clause for an update statement.
Was This Post Helpful? 0
  • +
  • -

#3 Mattster   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-December 18

Re: php and mysql query for Opencart.

Posted 12 December 2018 - 08:24 AM

No there's just one record. I created the table for the sole purpose of this.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1