PHP Integration http://forum.vaeplatform.com/categories/php-integration/feed.rss Thu, 31 Oct 13 01:29:34 -0400 PHP Integration en-CA Advanced Searching http://forum.vaeplatform.com/discussion/322/advanced-searching Mon, 18 Feb 2013 18:31:31 -0500 brandonsavoy 322@/discussions
Here is my code:


<v:php>
$search_results = array();
</v:php>
<v:collection path="/art[tags/name='<v=ucwords($tag)>']" unique="name">
<v:php>
array_push($search_results, $context['id']);
$my_image = vae_sizedimage($context['image'], 'Thumb160');
$path = vae_data_url() . $my_image;
return '<img src="' . $path . '" />';
</v:php>
</v:collection>

<v:collection path="/art" filter_input="tag" unique="name">
<v:if path="count($search_results)>0">
<v:if path="CHECKID(<v->)" is="true">
<v:php>
$my_image = vae_sizedimage($context['image'], 'Thumb160');
$path = vae_data_url() . $my_image;
return '<img src="' . $path . '" />';
</v:php>
</v:if>
<v:else>
<v:php>
$my_image = vae_sizedimage($context['image'], 'Thumb160');
$path = vae_data_url() . $my_image;
return '<img src="' . $path . '" />';
</v:php>
</v:else>
</v:if>
</v:collection>

in my __vae.php
function CHECKID(myID)
{
$showMe = "true";
foreach($search_results as $result)
{
if(myID == $result) $showMe = "false";
}
return $showMe;
}



It seems like the count check is working but it doesn't look like my CHECKID() function call I am making in the v:if line is...

Any help on how to solve this and / or do another way would be greatly appreciated.

Thanks,
Brandon
]]>
3rd party fulfillment integration http://forum.vaeplatform.com/discussion/131/3rd-party-fulfillment-integration Fri, 15 Jul 2011 09:34:29 -0400 crvn 131@/discussions
Anyone ever do this before with Vae?

Right now I am starting the process using the API and custom scripts. ]]>
Tax class overriding http://forum.vaeplatform.com/discussion/319/tax-class-overriding Thu, 20 Dec 2012 15:12:02 -0500 dmitrivassilev 319@/discussions
We are trying to add a no_tax tax_class for things like gift cards. Unfortunately, we have tax rules set up for NJ/NY that are automatically triggering if the shipment is to either of those states.

Is there any easy way to have a particular tax class completely override any others that may apply?

Basically, we still want NJ/NY orders to receive their tax class but ONLY IF the item doesn't also have a no_tax rule associated with it.

Is this possible? FYI, we are using the PHP API to integrate add_to_cart for AJAX purposes.

Dmitri]]>
v:else doesn't render when using custom tags http://forum.vaeplatform.com/discussion/307/velse-doesnt-render-when-using-custom-tags Wed, 08 Aug 2012 08:45:06 -0400 ceinarsrud 307@/discussions
I've created a custom PHP function in __vae.php:
function check_device($a, $tag, $context, &$callback) {
$detect = new Mobile_Detect();
$device = ($detect->isMobile() || $detect->isTablet()) ? 'mobile' : 'desktop';
return vae_render_tags($tag, $context, ($a['device'] == $device));
}

vae_register_tag('check_device', array(
'handler' => 'check_device',
'params' => array("device"),
'required' => array("device")
));


I use this syntax:
<v:check_device device="mobile">
User is on mobile
</v:check_device>
<v:else>User is on desktop</v:else>

For some reason the content of v:else won't render when the php-function returns false. Am I doing something wrong here?

I've based my code on the IfCurrentDomain example at http://docs.vaeplatform.com/php_vae_register_tag]]>
PHP includes in local dev http://forum.vaeplatform.com/discussion/61/php-includes-in-local-dev Wed, 08 Dec 2010 14:49:57 -0500 dmitry 61@/discussions Using vae_update to increment a value http://forum.vaeplatform.com/discussion/296/using-vae_update-to-increment-a-value Fri, 22 Jun 2012 13:52:05 -0400 adam_crvn 296@/discussions

$exhibition = vae($resourceId);
$votes = $exhibition['votes'];
$intVotes = intval($votes) + 1;
vae_update($exhibition->id, array('votes' => $intVotes));



Regardless of whether the 'votes' field has no value or a number, it sets the field value to 2. Setting a var to vae_update always returns true.]]>
Partial support for Vae http://forum.vaeplatform.com/discussion/295/partial-support-for-vae Wed, 20 Jun 2012 04:38:33 -0400 sbrekken 295@/discussions
Syntax

To register a partial simply wrap your code in a v:partial tag:

<v:partial id="product">
<v:img path="image" />

<v:if path="price">
<div class="price"><v:text path="price" /></div>
</v:if>

<div class="name" title="<v:text path="name" />"><v:text path="name" /></div>
</v:partial>


... and then to use that partial in any context (single document or collection):

<div class="featured product">
<v:partial id="product" path="/products[price > 0]" />
</div>

<ul class="products">
<li><v:partial id="product" path="/products" /></li>
</ul>


Note: The partial output tag takes the same parameters as v:collection.

Code (put this in __vae.php):

function partial($attributes, $tag, $context, $callback) {
global $partials;

$id = $attributes['id'];

if (count($tag['tags']) > 0) {
if (!is_array($partials)) {
$partials = array();
}

$partials[$id] = $tag;
} else {
if (array_key_exists('path', $attributes)) {
$context = vae($attributes['path']);
}

return vae_render_tags($partials[$id], $context);
}
}

vae_register_tag('partial', array(
'handler' => 'partial',
'params' => 'collection',
'required' => array('id')
));
]]>
Multi-language translation implementation http://forum.vaeplatform.com/discussion/294/multi-language-translation-implementation Wed, 20 Jun 2012 04:22:18 -0400 sbrekken 294@/discussions
Syntax

<span><v:t>Hello world!</v:t></span> => <span>Bonjour tout le monde</span>


Single language

This assumes you're only translating from the original language to the second language (you could easily upgrade this to support additional languages by using the multi-language variant below).

Setting either _GET[lang] or _COOKIE[lang] enables translation.

Required structure:

• Settings
    • Translations
        • Text - Text (e.g "About us")
        • Translation - Text (e.g "A propos de nous")

Code (put this in __vae.php):

function translate($attributes, $tag, $context, $callback) {
$locale = $_REQUEST['lang'];
$key = vae_render_tags($tag, $context);

if ($locale) {
$language = language($locale);

if ($language) {
$translation = (string)vae(sprintf('settings/translations[text="%s"][language=%d]', $key, $language->id))->translation;

if ($translation) {
return $translation;
}
}
}

return $key;
}

vae_register_tag('t', array(
'handler' => 'translate'
));


Multi-language translation

This implementation supports any number of languages but with the cost of extra complexity.

Required structure:
• Settings
    • Languages
        • Name - Text (e.g. "English")
        • Locale code - Text (e.g "en")

    •Translation names
        • Name - Text (e.g "About us")

    • Translations
        • Language - Single association to Languages
        • Name - Single association to Translation names
        • Translation - Text (e.g "A propos de nous")

Code (put this in __vae.php):

function translate($attributes, $tag, $context, $callback) {
$key = $tag['tags'][0]['innerhtml'];
$settings = vae('settings');

$translationId = (int)$settings->get(sprintf('translation_names[name="%s"]', $key))->id;

if ($translationId) {
$languageCode = $_REQUEST['lang'];
$languageId = (int)$settings->get(sprintf('languages[%s]', $languageCode ? sprintf('locale_code="%s"', $languageCode) : 1))->id;

if ($languageId) {
$translation = (string)$settings->get(sprintf('translations[name=%d][language=%d]', $translationId, $languageId))->translation;

if ($translation) {
return $translation;
}
}
}

return $key;
}

vae_register_tag('t', array(
'handler' => 'translate'
));
]]>
vae_store_orders() product ids for items in orders http://forum.vaeplatform.com/discussion/285/vae_store_orders-product-ids-for-items-in-orders Wed, 04 Apr 2012 17:46:02 -0400 sebbean 285@/discussions
Each order has an 'items' array that lists each product that was purchased. (example pasted below)

each item in this array has many id's within it:
[id] => 137912
[option_id] => 373227
[row_id] => 373206
[store_order_id] => 76448

However none of these correspond with the id of the product that was purchased. also the option_id does not correspond to a proper option_id in the system (at least my current system).

I'm trying to build a script to sync inventory between a POS system and the VAE backend database and I need to be able to pull up the vae product/options object to sync.


example:
[items] => Array
(
[137912] => Array
(
[backstage_notes] =>
[barcode] =>
[brand] =>
[bundled_with] =>
[cancelled] =>
[category] =>
[created_at] => 2011-01-13T11:45:05-05:00
[deleted] =>
[discount_reason] =>
[id] => 137912
[inventory_applied] => 1
[inventory_field] => inventory
[name] => Surf Slash
[notes] =>
[option_id] => 373227
[options] => Navy/X-Large
[original_price] => 30.0
[position] => 2
[price] => 30.0
[price_original] =>
[qty] => 1
[qty_original] =>
[row_id] => 373206
[store_order_id] => 76448
[tax] => 0.0
[total] => 30.0
[updated_at] => 2011-01-13T11:45:05-05:00
)]]>
PHP Has Been Updated to 5.3.6 http://forum.vaeplatform.com/discussion/143/php-has-been-updated-to-5.3.6 Sat, 20 Aug 2011 11:59:19 -0400 Kevin 143@/discussions
We have finally updated our version of PHP to 5.3.6.

This is something I've put off for a long time because of the huge amount of our stack that depends on PHP, however, PHP 5.3 has now been out for over 2 years, and we'd like to keep with the times.

Let me know if you see any problems; I hope you enjoy!]]>
Items are not saved in cart when testing in local, in CHROME only http://forum.vaeplatform.com/discussion/154/items-are-not-saved-in-cart-when-testing-in-local-in-chrome-only Wed, 14 Sep 2011 16:35:45 -0400 Steve 154@/discussions Mailchimp Integration http://forum.vaeplatform.com/discussion/156/mailchimp-integration Wed, 21 Sep 2011 13:36:57 -0400 Kevin 156@/discussions
Well, here's an example of how we did it:
http://assets.vaeplatform.com/tutorial_files/mailchimp-vae-example.zip

Unzip this into the root of your Vae website. If you already have an __vae.php file, you might want to merge this one into your existing one.

Edit __vae.php to specify your Mailchimp API key and list ID.

In this example, we add someone to your list if they submit a <v:formmail> tag. But, you could change that hook to hook into any tag (or call the function directly).

Hope this helps!]]>
__vae.php - error messages http://forum.vaeplatform.com/discussion/157/__vae.php-error-messages Thu, 22 Sep 2011 10:55:45 -0400 adam_crvn 157@/discussions
And maybe more generally, are there recommended best practices for debugging __vae.php ?]]>
SOAP Integration http://forum.vaeplatform.com/discussion/132/soap-integration Fri, 15 Jul 2011 16:42:29 -0400 crvn 132@/discussions
Does the vae hosting system support this? Usual PHP installs can be configured to have the standard SOAP library accessible. (http://www.php.net/manual/en/ref.soap.php)

Any thoughts on how to use these libraries w/ Vae?]]>
'Expires' and 'Cache-Control' cache headers http://forum.vaeplatform.com/discussion/89/expires-and-cache-control-cache-headers Wed, 16 Feb 2011 01:05:20 -0500 algesten 89@/discussions @font-face included type faces (yes they're licensed). To work cross platform the fonts are stored in various file formats (.eot, .svg, .ttf, .woff).

The fonts are rather heavy and I'd like to control cache headers to ensure the browser does not re-request them.

It seems 'Last-Modified' is set to that of the timestamp of the file, which is nice since it provokes If-Modified-Since behaviour. 'Cache-Control' is set to max-age=0, which works for this.

However I want to make it even better, stopping the browser from asking altogether using future 'Expires' and 'Cache-Control'.

If these were .html or .php files I assume I could use the global php include to modify headers, but my file endings are not processed (according to docs).

Is it possible to do what I want?]]>
Sending custom Emails http://forum.vaeplatform.com/discussion/83/sending-custom-emails Wed, 02 Feb 2011 13:26:40 -0500 dmitry 83@/discussions
Is there any way I could call something like what v:store:checkout does with the email_confirmation attribute?]]>
User Registration in PHP http://forum.vaeplatform.com/discussion/30/user-registration-in-php Mon, 25 Oct 2010 18:31:29 -0400 dmitry 30@/discussions http://docs.vaeplatform.com/vaeml_users_tags]]> Date Formatting w/ PHP http://forum.vaeplatform.com/discussion/50/date-formatting-w-php Sat, 13 Nov 2010 13:11:55 -0500 Scott 50@/discussions <?php foreach (vae("/partners[name='Discovery']") as $partner) {echo $partner->delivery_date;} ?>
That returns a string like 1290488400, but I need to return a string like November 24, 2010. Any Ideas?

I tried using this but it doesn't render anything:
echo(date('F d, Y', $partner->delivery_date));]]>
ZIP Code Search http://forum.vaeplatform.com/discussion/42/zip-code-search Wed, 03 Nov 2010 02:40:52 -0400 Kevin 42@/discussions
The new function is vae_zip_distance($from, $to). $from is the starting ZIP code and $to is the destination ZIP code. It returns a distance in miles. If $to is an array of ZIP codes, the function will return an associative array mapping the destination ZIP code to the distance.

If $to is a Vae object, the function will pull the ZIP code for each object by looking in the "zip" structure under that object. You may change the name of the structure we look for by passing it in as a third parameter. This mode will still return an associative array mapping the destination ZIP code to the distance, however it will also add an attribute "distance" to each Vae object passed in. This enables you to then filter by that.

Here's an example of showing stores in the Stores collection that are within 50 miles of the ZIP code passed in via the request parameter $zip:

$stores = vae("stores");
$distances = vae_zip_distance($_REQUEST['zip'], $stores);
foreach ($stores as $store) {
if ($store->distance < 50) {
echo $store->name . " (" . number_format($store->distance, 2) . "miles away)\n";
}
}


If you wanted to do some sorting, you could use the PHP usort() function. This example would show the stores sorted from closest to farthest:

function sort_by_distance($a, $b) {
return ($a->distance > $b->distance);
}

$stores = vae("stores");
$distances = vae_zip_distance($_REQUEST['zip'], $stores);
$stores = $stores->toArray();
usort($stores, "sort_by_distance");
foreach ($stores as $store) {
echo $store->name . " (" . number_format($store->distance, 2) . "miles away)\n";
}


Let me know if you have any questions, and I hope you all enjoy the new feature. ]]>
Order of Execution http://forum.vaeplatform.com/discussion/22/order-of-execution Tue, 12 Oct 2010 22:51:45 -0400 Kevin 22@/discussions
1) When pages containing Vae code are rendered, is there a particular order of execution to how the code on the page will be processed? For example, I have a page that contains PHP code at the beginning, but the Vae code in the middle of page seems to complete first before the PHP code is executed.

2) With the _vae.php file are we able to insert any code that we need to have preemptively executed before the actually page is executed?]]>
Accessing the pagination with vae(); http://forum.vaeplatform.com/discussion/6/accessing-the-pagination-with-vae Thu, 16 Sep 2010 20:22:05 -0400 michael 6@/discussions

The markup would look like this:


<v:php>
function page($id) {
return $pagination_value;
}

</v:php>



<v:collection>
<a href="/press-image/page/<v?= page($id) ?>">Click here for image $id. </a>
</v:collection>


I think a good starting point is to take the attributes of the collection that I am trying to emulate the pagination for:


<v:collection path="press_images" id="press_collection" order="DESC(press/publication_date)" previous="previous" next="next" wrap="true" paginate="1">
</v:collection>


as a vae() function:


$press_images = vae( "press_images", array( "order" => "DESC(press/publication_date)", "paginate" => "1", "wrap"=>"true" ) );


but where do I go from there?

]]>
the debug method http://forum.vaeplatform.com/discussion/5/the-debug-method Thu, 16 Sep 2010 20:08:15 -0400 michael 5@/discussions
As an example:

$press_images = vae( "press_images");



return $press_images->debug;

just returns "Array"


return print_r($press_images->debug);

just returns "1"]]>