mardi 4 août 2015

How to add "you save" option in the shopping cart of opencart?

I am trying to create a you save option in the shopping cart of opencart.com. I have done the same feature of you save to be displayed in the product page using vqmod. But i am finding it difficult to do it for the shopping cart. here is my vqmod code for adding you save option in the product page.

<modification>
    <id><![CDATA[@tik Savings Note]]></id>
    <version><![CDATA[1.1]]></version>
    <vqmver><![CDATA[2.1.7]]></vqmver>
    <author><![CDATA[OC2PS]]></author>
    <file name="catalog/view/theme/default/template/product/product.tpl">
        <operation>
            <search position="before" offset="2" error="log"><![CDATA[<?php if ($tax) { ?>]]></search>
            <add><![CDATA[<br /><span class="you-save" style="color:red;"><?php echo $text_yousave; ?> <?php echo $yousave; ?></span>]]></add>
        </operation>
    </file>
    <file name="catalog/language/english/product/product.php">
       <operation>
            <search position="replace" error="log"><![CDATA[// Entry]]></search>
            <add><![CDATA[$_['text_yousave']        = 'You save:';// Entry]]></add>
       </operation>
    </file>
    <file name="catalog/controller/product/product.php">
        <operation>
            <search position="replace" error="log"><![CDATA[$data['text_tax'] = $this->language->get('text_tax');]]></search>
            <add><![CDATA[$data['text_tax'] = $this->language->get('text_tax');
                 $data['text_yousave'] = $this->language->get('text_yousave');]]></add>
        </operation>
        <operation>
            <search position="replace" error="log"><![CDATA[$data['special'] = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')));]]></search>
            <add><![CDATA[$data['special'] = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')));
                $data['yousave'] = $this->currency->format($this->tax->calculate($product_info['price']-$product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')));
                $data['yousavepercent'] = round(($product_info['price']-$product_info['special'])*100/$product_info['price'],0);]]></add>
        </operation>
        <operation>
            <search position="replace" error="log"><![CDATA[$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));]]></search>
            <add><![CDATA[$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
                    $yousave = $this->currency->format($this->tax->calculate($result['price']-$result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
                    $yousavepercent = round(($result['price']-$result['special'])*100/$result['price'],0);]]></add>
        </operation>        
    </file>
</modification>

Signing JSON objects

I have to exchange JSON objects between different platforms and implementations of a service and make its integrity verifiable via digital signatures. So a platform A would create such an object and create a digital signature. Said signature is then included into the object and sent to platform B. The JSON objects can contain arbitrary attributes and data.

E.g. in PHP:

function signObject($jsonObjectToSign, $privateKey) {
    $jsonObjectToSign->signature = "";
    $msgToSign = json_encode($jsonObjectToSign);

    openssl_sign($msgToSign, $jsonObjectToSign->signature, $privateKey, OPENSSL_SLGO_SHA1);

    return $jsonObjectToSign;
}

Problem is, that e.g. in Java, there is no way to tell whether the attributes of a JSON object will be in the same order you added them (via JSONObject.put()). So, if I do a

$json = json_encode('{"a":1, "b":2}');

in PHP, sign this object as stated above, transfer it to a java based server, decode the json object and then try to verify the signature, I'd probably get a different order of the object's attributes.

So what I need, is a reliable way to create a String from a JSONObject, independent of the language or platform used.

The example object above needs always to output {"a":1, "b":2} and NEVER {"b":2, "a":1}. Unfortunately, this is the usual case e.g. in Java.

Is there any "best practice" to sign JSON Objects in a secure way?

But let me describe the problem in another way:

Let's say I want to do this in Java (or any other language):

JSONObject j = new JSONObject();
j.put("a", 1);
j.put("b", 2);

Now, I need a serialization function, that outputs always the same string representation for this object, no matter how and with what language this object is created.

MySQL trigger: updating column depending of a submitted value

Ths my trigger but it doesn't work.

CREATE TRIGGER events_events_a BEFORE INSERT ON events_events
FOR EACH ROW
BEGIN 
IF NEW.public = 1 THEN
UPDATE events_cats SET etotal=etotal+1, etotal_NEW.region=etotal_NEW.region+1 WHERE id=NEW.category;
END IF;
END;

I need to update column depending of a submitted value.

if NEW.region value is 1, I need to update column etotal_1=etotal_1+1
if NEW.region value is 2, I need to update column etotal_2=etotal_2+1
if NEW.region value is 3, I need to update column etotal_3=etotal_3+1

etc. Is there any way how to update column depending of NEW.region value?

How to write NULL instead of 0 when I leave a field empty

I have a problem with inserting data. When I leave a field empty then he writes a 0 in my db instead of 0. What I have to do that he writes NULL.

<?php

if ($date == '' || $name_home == ''|| $name_away == '')
{

$error = 'Please enter the details!';

valid($date, $name_home, $name_away, $score_home, $score_away, $error);
}
else
{

mysql_query("INSERT name_matches SET date='$date', name_home='$name_home', name_away='$name_away', score_home='$score_home', score_away='$score_away'")
or die(mysql_error());

header("Location: view.php");
}
}
else
{
valid('','','','','','');
}
?>

Divs, including php to appear next to each eachother

Using Bootstrap to layout the page and at first I had images in a grid, like on Facebook, there were 4 in a row and as the page shrunk so did the number of images in a row. Now I have added php so it is easier to update the page but the images all appear under each other. How can I have it the way it was?

Code used:

<section  id="alf40">
   <div class="container-fluid no-padding ">
<div class="row">

        <div class="col-lg-3 col-md-4 col-xs-6 thumb" style="display:inline-block; float:left; position:relative;" >
        <?php $SQL = "SELECT * FROM nw_photo";
        $result = mysql_query($SQL);
        while ( $db_field = mysql_fetch_assoc($result) ) { ?>

            <a class="thumbnail" href="#"><img class="img-responsive" src="
    <?php echo $db_field['image']; ?>" style="display:inline-block; float:left; position:relative;">
            <?php } ?></a>
        </div>

</div>
</div>
  </section>

Alternative to strtotime() in MySQL

I have an EventSet table with those fields:

  • start_day (ex. Monday)
  • start_time (ex. 14:20:00)

I want to create a query that selects specific records by comparing their day an time with the current ones.

So, using a little help from the PHP's strtotime() method I am aiming at something similar to:

SELECT * 
FROM 
   `EventSet` 
WHERE 
    DATE_FORMAT(NOW(), '%W %H:%i:%s') <= 
    date('%W %H:%i:%s', strtotime('start_day start_time'))

*the last date() part is of course pure PHP


So far I've tried using DATE_FORMAT with CONCAT_WS and also TIMESTAMP() / UNIX_TIMESTAMP() but am clearly messing something up.

SELECT * 
FROM 
    `EventSet` 
WHERE 
    DATE_FORMAT(NOW(), '%W %H:%i:%s') <= 
    DATE_FORMAT(CONCAT_WS(' ', start_day, start_time), '%W %H:%i:%s')

I've looked through many similar questions here and in the net, but they all already have a date field to work with and there's no need to concatenate anything, so I can't use any of them.

How to access protected variable form given response [duplicate]

This question already has an answer here:

I want to retrieve _href:protected from given response but i don't know How i can access it .

 Recurly_Subscription Object
(
    [_values:protected] => Array
        (
            [subscription_add_ons] => Array
                (
                )

            [account] => Recurly_Stub Object
                (
                    [objectType] => account
                    [_href:protected] => http://ift.tt/1MJI9ao
                    [_client:protected] => Recurly_Client Object
                        (
                            [_apiKey:Recurly_Client:private] => 
                            [_acceptLanguage:Recurly_Client:private] => en-US
                        )

                    [_links:protected] => Array
                        (
                        )

                )






)
)

i try $sub->account->href for account href but not success. Please provide solution .