function _promoMethodList() { $conds = array(); $methods = array(); if (ShopConfig::load('promo.complexBehavior') || ShopConfig::load('promo.complexConditions')) { App::import('Lib', 'Shop.ClassCollection'); $all = ClassCollection::getList('promo', 'flat'); foreach ($all as $name => $label) { $class = ClassCollection::getClass('promo', $name); if (!method_exists($class, 'isAvailable') || call_user_func(array($class, 'isAvailable'))) { $obj = new $class(); if (method_exists($class, 'beforeForm')) { $obj->beforeForm($this); } if (!empty($obj->type) && ($obj->type = 'condition')) { $conds[$name] = $obj; } else { $methods[$name] = $obj; } } } } if (!ShopConfig::load('promo.complexConditions')) { $conds = array(); } if (!ShopConfig::load('promo.complexBehavior')) { App::import('Lib', 'Shop.ClassCollection'); $class = ClassCollection::getClass('promo', 'Shop.operation'); $obj = new $class(); $methods = array('Shop.operation' => $obj); } return array('methods' => $methods, 'conds' => $conds); }
function __construct() { App::import('Lib', 'Shop.ShopConfig'); $this->settings = ShopConfig::load('payment.' . $this->name); if (!isset($this->ShopPayment)) { $this->ShopPayment = ClassRegistry::init(array('class' => 'Shop.ShopPayment', 'alias' => 'ShopPayment')); } //debug('Shop.payment.'.$this->name); }
function beforeFilter() { parent::beforeFilter(); App::import('Lib', 'Shop.ShopConfig'); $enabled = ShopConfig::load('enabled'); if (!$enabled) { $this->log('Shop is disabled', LOG_DEBUG); $this->redirect(array('plugin' => 'auth', 'controller' => 'users', 'action' => 'permission_denied', 'admin' => false)); } }
function beforeRender() { App::import('Lib', 'Shop.ShopConfig'); if (ShopConfig::load('cart.qtyInNbItem')) { $this->controller->params['Shop']['nbItem'] = $this->getTotalQty(); } else { $this->controller->params['Shop']['nbItem'] = $this->nbItem(); } $this->controller->params['Shop']['qtys'] = $this->qtysByProduct(); }
function index() { $prevUrl = null; if (!empty($_SERVER['HTTP_REFERER']) && !$this->ShopFunct->isInternalUrl($_SERVER['HTTP_REFERER'])) { $prevUrl = $_SERVER['HTTP_REFERER']; } if (!empty($this->params['named']['redirect'])) { App::import('Lib', 'Shop.UrlParam'); $prevUrl = UrlParam::decode($this->params['named']['redirect']); } if (!empty($this->data)) { if (!empty($this->data['ShopOrder']['promo_codes'])) { $tmp = array(); App::import('Lib', 'Shop.ShopConfig'); $max = ShopConfig::load('promo.max'); foreach ($this->data['ShopOrder']['promo_codes'] as $code) { if (!empty($max) && count($tmp) >= $max) { break; } if (!empty($code) && (empty($tmp) || !in_array($code, $tmp))) { $tmp[] = $code; } } //debug($tmp); unset($this->data['ShopOrder']['promo_codes']); $this->CartMaker->data['order']['promo_codes'] = $tmp; } if (!empty($this->data['ShopCart']['redirect'])) { $prevUrl = $this->data['ShopCart']['redirect']; } if (!empty($this->data['ShopCart']['order']['shipping_postal_code'])) { $location = $this->CartMaker->gessLocation($this->data['ShopCart']['order']['shipping_postal_code']); if (!empty($location)) { foreach ($location as $key => $val) { if (!empty($val)) { $this->data['ShopCart']['order']['shipping_' . $key] = $val; } } } } //debug($this->data); $this->CartMaker->save($this->data); } else { //debug($this->data); } $this->data = $this->CartMaker->toData(); if (!empty($this->data['ShopCart']['order'])) { $this->data['ShopOrder'] = $this->data['ShopCart']['order']; } //debug($this->data); $data = $this->CartMaker->calculate(); $cartItems = $data['items']; $calcul = $data; unset($calcul['items']); $this->set('cartItems', $cartItems); $this->set('calcul', $calcul); $this->Component->triggerCallback('shopCartBeforeRender', $this); if (isset($this->data['ShopOrder']['promo_codes'])) { $codesValidation = $this->ShopPromotion->codesExists($this->data['ShopOrder']['promo_codes'], false, true); $this->set('codesValidation', $codesValidation); } $codePromos = $this->ShopPromotion->find('count', array('conditions' => array('or' => array('code_needed' => 1, 'coupon_code_needed' => 1)))); $this->set('codeInput', $codePromos > 0); $defaultReturn = ShopConfig::load('cart.defaultReturn'); if (empty($prevUrl) && !empty($defaultReturn)) { $prevUrl = $defaultReturn; } $this->set('prevUrl', $prevUrl); if (isset($this->params['named']['display']) && $this->params['named']['display'] == 'print') { $this->layout = 'print'; $this->render('print_cart'); } }
function cartLink($options = array()) { App::import('Lib', 'Shop.ShopConfig'); $enabled = ShopConfig::load('enabled'); if (!$enabled) { return ''; } $defaultOptions = array('label' => __("Your cart (%nbItem%)", true), 'class' => array('cart')); if (!empty($options) && !is_array($options)) { $options = array('label' => $options); } $opt = array_merge($defaultOptions, $options); $label = $opt['label']; if (!empty($this->params['Shop'])) { foreach ($this->params['Shop'] as $key => $val) { if (!is_array($val)) { $label = str_replace('%' . $key . '%', $val, $label); } } } return $this->Html->link($label, array('plugin' => 'shop', 'controller' => 'shop_cart', 'action' => 'index'), $this->O2form->normalizeAttributesOpt($opt, array('label'))); }
function getSupplementOpts($type = null, $name = null) { $_this =& ShopConfig::getInstance(); $exportedSupplements = $_this->exportedSupplements; $default_supplement_opt = $_this->default_supplement_opt; $specific_default_sup_opt = $_this->specific_default_sup_opt; $default_supplement_name = $_this->default_supplement_name; $supplements = (array) ShopConfig::load('supplements'); foreach ($exportedSupplements as $sName) { $exportConf = ShopConfig::load($sName . 'Types'); if (!empty($exportConf)) { $supplements[$sName] = $exportConf; } } $opts = array(); foreach ($supplements as $tName => $supplementTypes) { if (is_null($type) || in_array($tName, (array) $type)) { $tOpts = array(); $specific_def = array(); if (!empty($specific_default_sup_opt[$tName])) { $specific_def = $specific_default_sup_opt[$tName]; } if (empty($supplementTypes)) { $supplementTypes[$default_supplement_name] = array(); } foreach ($supplementTypes as $sName => $setting) { if (is_null($name) || in_array($sName, (array) $name)) { if (!is_array($setting)) { $setting = array('price' => $setting); } $sOpts = Set::merge($default_supplement_opt, $specific_def, $setting); if (empty($sOpts['label']) && $sOpts['label'] !== false) { $sOpts['label'] = Inflector::humanize($tName); } if (isset($sOpts['label'])) { $sOpts['label'] = __($sOpts['label'], true); } if (empty($sOpts['title'])) { if (!empty($sOpts['descr'])) { $sOpts['title'] = $sOpts['descr']; } else { $sOpts['title'] = Inflector::humanize($sName); } } if (isset($sOpts['title'])) { $sOpts['title'] = __($sOpts['title'], true); } if (empty($sOpts['descr']) && $sOpts['descr'] !== false && $sName != $default_supplement_name) { $sOpts['descr'] = Inflector::humanize($sName); } if (isset($sOpts['descr'])) { $sOpts['descr'] = __($sOpts['descr'], true); } if (!empty($sOpts['calculFunction'])) { $sOpts['calcul'] = $sOpts['calculFunction']; } $sOpts['name'] = $sName; if (!is_null($name) && !is_array($name)) { return $sOpts; } $tOpts[$sName] = $sOpts; } } if (!is_null($type) && !is_array($type)) { return $tOpts; } $opts[$tName] = $tOpts; } } return $opts; }
function byCurrency($options, $supplementItem, $order, $supplement_choice, $calcul) { $defOpt = array('modifProp' => 'total', 'subMethod' => null, 'list' => array()); if (!count(array_intersect_key($options, $defOpt))) { $options = array('list' => $options); } $opt = array_merge($defOpt, $options); $currency = !empty($order['ShopOrder']['currency']) ? $order['ShopOrder']['currency'] : ShopConfig::load('currency'); $val = null; if (array_key_exists($currency, $opt['list'])) { $val = $opt['list'][$currency]; } elseif (array_key_exists('default', $opt['list'])) { $val = $opt['list']['default']; } if (!is_null($val)) { if (!empty($opt['subMethod'])) { return $this->calculFunct($opt['subMethod'], $val, $supplementItem, $order, $supplement_choice, $calcul); } $supplementItem[$opt['modifProp']] = $val; } return $supplementItem; }
function extractOrderItemData($productAndOptions, $order = null) { App::import('Lib', 'Shop.ShopConfig'); $currency = !empty($order['ShopOrder']['currency']) ? $order['ShopOrder']['currency'] : ShopConfig::load('currency'); $extract_data = array('id' => 'id', 'product_id' => 'ShopProduct.id', 'nb' => array('nb', 'Options.nb'), 'comment' => array('comment', 'Options.comment'), 'data' => array('data', 'Options.data'), 'item_title' => array('DynamicField.title', 'ShopProduct.DynamicField.title', 'ShopProduct.code'), 'item_descr' => array('DynamicField.descr', 'ShopProduct.DynamicField.descr'), 'item_price' => array('ShopProduct.DynamicField.price', 'DynamicField.price', 'Options.currency_prices.' . $currency, 'Options.price', 'ShopProduct.currency_prices.' . $currency, 'ShopProduct.price'), 'item_tax_applied' => array('ShopProduct.tax_applied'), 'ShopPromotion' => array('ShopProduct.ShopPromotion', 'ShopPromotion'), 'ShopSubproduct' => array('ShopProduct.ShopSubproduct', 'ShopSubproduct'), 'SubItem' => array('Options.SubItem', 'SubItem'), 'ShopOrdersSubitem' => array('ShopOrdersSubitem'), 'item_rebate' => 'DynamicField.rebate', 'item_original_price' => 'DynamicField.original_price', 'product_related_id' => array('ShopProduct.Related.id', 'Related.id'), 'shipping_req' => array('ShopProduct.shipping_req')); if (!empty($order['ShopOrder']['confirm'])) { $extract_data = Set::merge(array('item_title' => array('item_title'), 'item_price' => array('item_price'), 'item_desc' => array('item_desc'), 'item_tax_applied' => array('item_tax_applied')), $extract_data); } $data = array(); App::import('Lib', 'Shop.SetMulti'); $data = SetMulti::extractHierarchicMulti($extract_data, $productAndOptions); if (!isset($data['item_tax_applied']) || $data['item_tax_applied'] === null) { $data['item_tax_applied'] = ShopConfig::load('defaultTaxes'); } $data['active'] = 1; return $data; }
function ordered($id = null) { if (!$id && isset($this->params['named']['id']) && is_numeric($this->params['named']['id'])) { $id = $this->params['named']['id']; } if (!empty($this->data['ShopOrder']['id'])) { $id = $this->data['ShopOrder']['id']; } if (!$id) { $this->Session->setFlash(sprintf(__('Invalid %s', true), 'shop order')); $this->redirect(array('action' => 'index')); } $this->OrderFunct->tcheckAcl($id); App::import('Lib', 'Shop.ShopConfig'); if (ShopConfig::load('cart.clearOnCompleted')) { $this->CartMaker->clear(); } $this->ShopOrder->setupForFullData(); $order = $this->ShopOrder->read(null, $id); $this->data = $order; $this->set('order', $order); }
function send_email_buyer($order) { $this->Email->reset(); if (Configure::read('Member.siteName')) { $siteName = Configure::read('Member.siteName'); } elseif (Configure::read('config.siteName')) { $siteName = Configure::read('config.siteName'); } else { $siteName = trim(str_replace('http://', '', Router::url('/', true)), ' /'); } $default_conf = array('subject' => str_replace('%siteName%', $siteName, __('Your order at %siteName%', true)), 'to' => $order['ShopOrder']['billing_email'], 'sender' => $this->_getDefaultSender($order), 'replyTo' => null, 'sendAs' => 'both', 'template' => 'order_admin'); $devMode = $order['ShopOrder']['dev_mode'] ? true : null; App::import('Lib', 'Shop.ShopConfig'); $conf = ShopConfig::load('emailBuyer', $devMode); if (is_array($conf)) { if (!empty($conf['subject'])) { $conf['subject'] = __($conf['subject'], true); } $conf = array_merge($default_conf, $conf); } else { $conf = $default_conf; } $conf['to'] = $order['ShopOrder']['billing_email']; $conf['subject'] = str_replace('{id}', $order['ShopOrder']['id'], $conf['subject']); $this->EmailUtils->setConfig($conf); $this->EmailUtils->set('order', $order); $this->EmailUtils->set('siteName', $siteName); if (!$this->Email->send()) { Debugger::log('Cound not send Email to Buyer'); return false; } else { return true; } }
function actConfig() { $config = new ShopConfig(); $config->load(); $data['config'] = $config; $this->setTitle('Настройки'); $this->explorer[] = array('name' => 'Настройки'); $this->display($data, dirname(__FILE__) . '/admin_config.tpl.php'); }
function generateCode($validate = true) { $code = ''; App::import('Lib', 'Shop.ShopConfig'); $len = ShopConfig::load('promo.codeLen'); $chars = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'); for ($i = 0; $i < $len; $i++) { $code .= $chars[rand(0, count($chars) - 1)]; } if ($validate && $this->codesExists($code)) { return $this->generateCode(); } return $code; }
function dynamicFieldsExtractData($product = null, $opt = array()) { if (is_array($product) && isset($product['ShopProduct'][0])) { $product['ShopProduct'] = $product['ShopProduct'][0]; } if (is_object($product) && is_a($product, 'Model')) { $relatedModel = $product; } else { $relatedModel = $this->getRelatedClass($product); } if (empty($relatedModel)) { //debug($product); //debug('wtf'); } if (!empty($relatedModel) && !empty($this->extractDataCache[$relatedModel->name])) { return $this->extractDataCache[$relatedModel->name]; } $extract_data = $this->dynamicFields; $fieldNameReplace = array(); if ($relatedModel && $relatedModel->displayField && $relatedModel->displayField != 'id') { $fieldNameReplace['(Related.displayField)'] = 'Related.' . $relatedModel->displayField; } App::import('Lib', 'Shop.ShopConfig'); $currency = !empty($opt['order']['currency']) ? $opt['order']['currency'] : ShopConfig::load('currency'); if ($currency) { $fieldNameReplace['(currency)'] = strtolower($currency); } foreach ($extract_data as $fieldName => &$paths) { //vas chercher les nom de champs spécifié dans les options du model conserné. $retatedPos = array_search('(Related)', $paths); if ($retatedPos !== false) { $relatedFields = array(); if ($relatedModel) { if (!empty($relatedModel->productOptions[$fieldName . '_field'])) { $relatedFields = (array) $relatedModel->productOptions[$fieldName . '_field']; } //$relatedFields[] = $fieldName; foreach ($relatedFields as &$relatedField) { $relatedField = 'Related.' . $relatedField; } } array_splice($paths, $retatedPos, 1, $relatedFields); } $finalPaths = array(); foreach ($paths as $realFieldName) { $realFieldName = str_replace(array_keys($fieldNameReplace), array_values($fieldNameReplace), $realFieldName); if (!$this->_startsWith($realFieldName, 'ShopProduct')) { $finalPaths[] = 'ShopProduct.' . $realFieldName; } $finalPaths[] = $realFieldName; } $paths = $finalPaths; } //debug($extract_data); if (!empty($relatedModel)) { $this->extractDataCache[$relatedModel->name] = $extract_data; } return $extract_data; }
function add($options) { //séparer option et produits ? $defaultOptions = array('id' => null, 'order' => array(), 'products' => array(), 'redirect' => true); if (!is_array($options)) { $options = array('products' => array($options)); } if (!empty($options['products']) && is_array($options['products']) && empty($options['products'][0])) { $options['products'] = array($options['products']); } $options = array_merge($defaultOptions, $options); if (!empty($options['products'])) { foreach ((array) $options['products'] as $productOpt) { $productOpt = $this->ShopFunct->formatProductAddOption($productOpt); $conditions = $this->ShopFunct->productFindConditions($productOpt); $this->initShopOrder(); $this->ShopOrder->ShopProduct->Behaviors->attach('Containable'); $this->ShopOrder->ShopProduct->contain(array('ShopSubproduct')); if ($conditions !== false) { $product = array(); $product = $this->ShopOrder->ShopProduct->find('first', array('conditions' => $conditions)); } if (empty($product) && empty($productOpt['id'])) { $product_id = $this->ProductMaker->add($productOpt); if ($product_id) { $product = $this->ShopOrder->ShopProduct->read(null, $product_id); } } if (!empty($product)) { /*$optToData = array('nb','comment','data'); foreach($optToData as $optName){ if(!empty($productOpt[$optName])){ $product[$optName] = $productOpt[$optName]; } }*/ $product['Options'] = $productOpt; $products[] = $product; } else { //product not found } } } if (!$options['id']) { if (empty($products)) { if ($options['redirect']) { $this->controller->redirect(array('plugin' => 'shop', 'controller' => 'shop_orders', 'action' => 'empty_error')); } else { return false; } } $this->initShopOrder(); $this->ShopOrder->create(); $orderData = $this->ShopOrder->filterExposedfields($options['order']); $orderData['active'] = true; $orderData['status'] = 'input'; $orderData['currency'] = ShopConfig::load('currency'); App::import('Lib', 'Shop.ShopConfig'); if (ShopConfig::load('devMode')) { $orderData['dev_mode'] = 1; } $this->ShopOrder->save($orderData); $order_id = $this->ShopOrder->id; $aro = $this->OrderFunct->getAro(); $this->Acl->allow($aro, $this->ShopOrder); } else { $order_id = $options['id']; $this->OrderFunct->tcheckAcl($order_id); $orderData = $this->ShopOrder->filterExposedfields($options['order']); if (!empty($orderData)) { $orderData['id'] = $order_id; if (!$this->ShopOrder->save($orderData)) { $this->log('Could not save Order', LOG_DEBUG); } } } if (!empty($products)) { foreach ($products as $product) { $this->ShopOrder->ShopOrdersItem->create(); $data = $this->ShopFunct->extractOrderItemData($product); $subItems = $this->ShopFunct->extractSubItemData($data); //extract sub items //debug($subItems); $keep = array('product_id', 'nb', 'active'); $data = array_intersect_key($data, array_flip($keep)); $data['order_id'] = $order_id; if ($this->ShopOrder->ShopOrdersItem->save($data)) { ////////// save sub items ////////// if (!empty($subItems)) { foreach ($subItems as &$subItem) { $this->ShopOrder->ShopOrdersItem->ShopOrdersSubitem->create(); $subItem['shop_orders_item_id'] = $this->ShopOrder->ShopOrdersItem->id; if (!empty($subItem['parent'])) { $subItem['parent_id'] = $subItem['parent']['id']; } $keep = array('shop_product_subproduct_id', 'shop_subproduct_id', 'nb', 'parent_id', 'shop_orders_item_id', 'type', 'active'); $sData = array_intersect_key($subItem, array_flip($keep)); if ($this->ShopOrder->ShopOrdersItem->ShopOrdersSubitem->save($sData)) { $subItem['id'] = $this->ShopOrder->ShopOrdersItem->ShopOrdersSubitem->id; } else { $this->log('Could not save OrderSubitem', LOG_DEBUG); } unset($subItem); } } } else { $this->log('Could not save OrderItem', LOG_DEBUG); } } } if (!empty($order_id) && !empty($options['order']['promo_codes'])) { $this->setPromo($options['order']['promo_codes'], array('ShopOrder' => array('id' => $order_id), 'ShopProduct' => $products)); } if ($options['redirect'] && ($options['redirect'] != 'add' || !$options['id'])) { $this->controller->redirect(array('plugin' => 'shop', 'controller' => 'shop_orders', 'action' => 'add', $order_id, 'lang' => $this->controller->lang)); } else { return $order_id; } }
function add($id = null) { if (!$id && isset($this->params['named']['id']) && is_numeric($this->params['named']['id'])) { $id = $this->params['named']['id']; } $orders = array(); if (isset($this->params['named']['order'])) { $conditions = array(); $conditions['active'] = 1; $conditions['id'] = $this->params['named']['order']; $this->ShopPayment->ShopOrder->recursive = -1; $order = $this->ShopPayment->ShopOrder->find('first', array('conditions' => $conditions)); $orders[] = $order; } if (!$id && empty($orders)) { trigger_error(__("ShopOrdersController::add() - order not found", true), E_USER_ERROR); } if (!$id) { $data = array(); $this->ShopPayment->create(); $data['status'] = 'input'; $data['active'] = 1; App::import('Lib', 'Shop.ShopConfig'); $data['currency'] = !empty($orders[0]['ShopOrder']['currency']) ? $orders[0]['ShopOrder']['currency'] : ShopConfig::load('currency'); $this->ShopPayment->save($data); $payment_id = $this->ShopPayment->id; $aro = $this->__getAro(); $this->Acl->allow($aro, $this->ShopPayment); } else { $payment_id = $id; $this->__tcheckAcl($payment_id); } foreach ($orders as $order) { $data = array(); $this->ShopPayment->ShopOrdersPayment->create($data); $data['order_id'] = $order['ShopOrder']['id']; $data['amount'] = $order['ShopOrder']['total']; $data['payment_id'] = $payment_id; $this->ShopPayment->ShopOrdersPayment->save($data); } if (!$id) { $this->redirect(array('action' => 'add', $payment_id, 'lang' => $this->lang)); } else { $this->ShopPayment->Behaviors->attach('Containable'); $this->ShopPayment->contain(array('ShopOrdersPayment', 'ShopOrder' => array('ShopOrdersItem'))); $this->ShopPayment->ShopOrder->ShopProduct->fullDataEnabled = false; $payment = $this->ShopPayment->read(null, $payment_id); $availableTypes = Configure::read('Shop.payment.available'); $types = array(); foreach ($availableTypes as $type) { $component = $this->PaymentFunct->loadPaimentComponent($type); $component->payment = $payment; $types[$type] = $component->getData('listItem'); } $this->set("types", $types); } }
function analytics($order) { if (!empty($order) && $order['ShopOrder']['status'] == 'ordered') { $gaAccount = null; App::import('Lib', 'Shop.ShopConfig'); $gaAccountConf = ShopConfig::load('gaAccount'); if (preg_match('/^(\\w*)::(.*)$/', $gaAccountConf, $matches)) { $prefix = $matches[1]; $varName = $matches[2]; if ($prefix == 'var') { $view =& ClassRegistry::getObject('view'); if (!empty($view->viewVars[$varName])) { $gaAccount = $view->viewVars[$varName]; } } elseif ($prefix == 'conf') { $gaAccount = Configure::read($varName); } } else { $gaAccount = $gaAccountConf; } if (!empty($gaAccount)) { $script = ' var _gaq = _gaq || []; _gaq.push(["_setAccount", "' . $gaAccount . '"]); _gaq.push(["_addTrans", "' . $order['ShopOrder']['id'] . '", // order ID - required "' . $_SERVER['SERVER_NAME'] . '", // affiliation or store name "' . $order['ShopOrder']['total'] . '", // total - required "' . $order['ShopOrder']['total_taxes'] . '", // tax "' . $order['ShopOrder']['total_shipping'] . '", // shipping "' . $order['ShopOrder']['shipping_city'] . '", // city "' . $order['ShopOrder']['shipping_region'] . '", // state or province "' . $order['ShopOrder']['shipping_country'] . '" // country ]); '; foreach ($order['ShopOrdersItem'] as $item) { $script .= ' _gaq.push(["_addItem", "' . $order['ShopOrder']['id'] . '", // order ID - necessary to associate item with transaction "' . $item['product_id'] . '", // SKU/code - required "' . $item['item_title'] . '", // product name "", // category or variation "' . $item['final_price'] . '", // unit price - required "' . $item['nb'] . '" // quantity - required ]); '; } $script .= '_gaq.push(["_trackTrans"]);'; $this->Html->scriptBlock($script, array('inline' => false)); } } }