Skip to content

Instantly share code, notes, and snippets.

@jonathandavis
jonathandavis / updates.php
Created August 12, 2013 14:54
An example mass update query
<?php
function shopp_product_update_variants ( array $variants, array $data ) {
$table = DatabaseObject::tablename(Price::$table);
$refresh_summaries = ProductSummary::$_updates;
DB::query("UPDATE $table SET price='{$data['price']},modified='$refresh_summaries' WHERE id IN(' . join(',', $variants) . ')");
}
public function send ( $data, $resource = '' ) {
$request = http_build_query($data);
$apiurl = str_true($this->settings['testmode']) ? self::DEVURL : self::APIURL;
$url = array($apiurl, self::APIVERSION, $resource);
$options = array(
'headers' => array('Authorization' => 'Basic ' . base64_encode($this->settings['apikey'] . ':'))
);
<?php
function freebie () {
if ( $this->Cart->orderisfree() ) {
$this->processor = 'FreeOrder';
$this->processor($this->processor);
$this->Billing->cardtype = __('Free Order','Shopp');
} elseif ( 'FreeOrder' == $this->processor ) {
// If the order is not free, but the order processor is still set to free order,
// reset the processor to use the default
$products = self::$products;
$quantities = array(1, 8, 6, 12);
$items = array();
foreach ( $products as $i => $Product ) {
$Item = new Item ( $Product, false );
$Item->quantity( $quantities[$i] );
$items[ $Item->fingerprint() ] = $Item;
}
ShoppOrder()->Cart->populate($items);
<?php
foreach ( $products as $i => $Product ) {
$quantity = ( $i % 2 ) ? 1 : ($i % count($products) + 1) * ($i % 3 + 1) ;
$Item = new Item ( $Product, false );
$Item->quantity( $i + $quantity );
$items[ $Item->fingerprint() ] = $Item;
}
ShoppOrder()->Cart->populate($items);
<?php
$products = self::$products;
$items = array();
for ($i = 0; $i < ( 2 * count($products) ); $i++ ) {
$p = $i % count($products);
if ( isset($items[$p]) ) $items[$p]->quantity($items[$p]->quantity + ($p + 1) * ($i % 3 + 1) );
else {
$items[$p] = new Item($products[$p], false);
$items[$p]->quantity($i + 1);
}
<?php
/**
* PackagingTests
*
*
* @author John Dillick
* @version 1.0
* @copyright Ingenesis Limited, 6 April, 2011
* @package
**/
diff --git a/core/flow/Categorize.php b/core/flow/Categorize.php
index 71addec..89ca8c9 100644
--- a/core/flow/Categorize.php
+++ b/core/flow/Categorize.php
@@ -423,7 +423,11 @@ class Categorize extends AdminController {
$meta = array('spectemplate','facetedmenus','variations','pricerange','priceranges','specs','options','prices');
$metadata = array_filter_keys($_POST,$meta);
foreach ($metadata as $name => $data) {
- if (!isset($Category->meta[$name])) new MetaObject();
+ if ( ! isset($Category->meta[ $name ]) ) {
const PROCESS = 'checkout';
public static function submitted () {
return isset($_POST[ self::PROCESS ]) && 'process' == $_POST[ self::PROCESS ];
}
if ( ! self::submitted() ) return;
<?php
$address = '125-S Main St';
$number = ''; $firstword = ''; $count = 1;
sscanf($address, '%d-%s', $number, $firstword);
if ( ! empty($number) && ! empty($firstword) )
$address = str_replace('-', '', $address, $count);
echo $address;