From: Verdon V. <ve...@us...> - 2009-03-04 14:42:42
|
Update of /cvsroot/phpwebsite-comm/modules/vshop/class In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv18882/class Modified Files: vShop.php vShop_Forms.php vShop_Item.php vShop_Runtime.php Added Files: vShop_Attribute.php Log Message: working on attributes Index: vShop_Runtime.php =================================================================== RCS file: /cvsroot/phpwebsite-comm/modules/vshop/class/vShop_Runtime.php,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** vShop_Runtime.php 25 Nov 2008 15:19:30 -0000 1.1.1.1 --- vShop_Runtime.php 4 Mar 2009 14:39:53 -0000 1.2 *************** *** 106,110 **** $item = new vShop_Item($result[0]['id']); $tpl['NAME'] = $item->viewLink(); ! $tpl['ADD'] = $item->addLink(true) . ' ' . $item->addLink(); if ($item->file_id) { $tpl['THUMBNAIL'] = $item->getThumbnail(true); --- 106,114 ---- $item = new vShop_Item($result[0]['id']); $tpl['NAME'] = $item->viewLink(); ! if ($item->getQtyAttributes() < 1) { ! $tpl['ADD'] = $item->addLink(true) . ' ' . $item->addLink(); ! } else { ! $tpl['ADD'] = sprintf('<a href="%s">', $item->viewLink(true)) . dgettext('vshop', 'Choose Options') . '</a>'; ! } if ($item->file_id) { $tpl['THUMBNAIL'] = $item->getThumbnail(true); Index: vShop_Item.php =================================================================== RCS file: /cvsroot/phpwebsite-comm/modules/vshop/class/vShop_Item.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** vShop_Item.php 2 Dec 2008 19:43:15 -0000 1.2 --- vShop_Item.php 4 Mar 2009 14:39:53 -0000 1.3 *************** *** 271,274 **** --- 271,397 ---- + public function getAllAttributes($limit=false) + { + PHPWS_Core::initModClass('vshop', 'vShop_Attribute.php'); + $db = new PHPWS_DB('vshop_attributes'); + $db->addOrder('set_id asc'); + $db->addWhere('item_id', $this->id); + if ($limit) { + $db->setLimit((int)$limit); + } + $result = $db->getObjects('vShop_Attribute'); + return $result; + } + + + public function getOptionSets($print=false,$form=true) + { + if ($this->getQtyAttributes() == 0) { + return null; + } + + $all_sets = null; + $choices = null; + $buttons = null; + $boxes = null; + $match = null; + + /* get the sets */ + $db = new PHPWS_DB('vshop_attributes'); + $db->addWhere('item_id', $this->id); + $db->addColumn('set_id', null, null, false, true); + $set_ids = $db->select(); + + foreach ($set_ids as $set) { + $db = new PHPWS_DB('vshop_option_sets'); + $db->addWhere('id', $set['set_id']); + $o_set = $db->select('row'); + + /* get the values */ + $db = new PHPWS_DB('vshop_attributes'); + $db->addWhere('item_id', $this->id); + $db->addWhere('set_id', $set['set_id']); + $value_ids = $db->select(); + + foreach ($value_ids as $value) { + $db = new PHPWS_DB('vshop_option_values'); + $db->addWhere('id', $value['value_id']); + $db->addOrder('sort asc'); + $s_values = $db->select('row'); + + if ($print) { // print + // not sure about print yet + } elseif ($form) { // form + $mods = null; + if ($value['price_mod'] > 0) { + if (PHPWS_Settings::get('vshop', 'curr_symbol_pos') == 1) { + $mods[] = $value['price_prefix'].PHPWS_Settings::get('vshop', 'currency_symbol').$value['price_mod']; + } else { + $mods[] = $value['price_prefix'].$value['price_mod'].PHPWS_Settings::get('vshop', 'currency_symbol'); + } + } + if ($value['weight_mod'] > 0) { + $mods[] = $value['weight_prefix'].$value['weight_mod'].PHPWS_Settings::get('vshop', 'weight_unit'); + } + if ($mods) { + $mods = '(' . implode(', ', $mods) . ')'; + } + if ($o_set['type'] == 1) { // list + $choices[$set['set_id']][$value['value_id']] = $s_values['title'].' '.$mods; + } elseif ($o_set['type'] == 2) { // buttons + $buttons .= PHPWS_Form::formRadio('options['.$set['set_id'].']', $value['value_id'], $match, null, $s_values['title'].' '.$mods) . "<br />\n"; + } elseif ($o_set['type'] == 3) { // checkboxes + $boxes .= PHPWS_Form::formCheckBox('options['.$set['set_id'].'][]', $value['value_id'], $match, null, $s_values['title'].' '.$mods) . "<br />\n"; + } + } else { // array + $all_sets[$set['set_id']]['values']['value_'.$value['value_id']]['id'] = $s_values['id']; + $all_sets[$set['set_id']]['values']['value_'.$value['value_id']]['title'] = $s_values['title']; + $all_sets[$set['set_id']]['values']['value_'.$value['value_id']]['price_prefix'] = $value['price_prefix']; + $all_sets[$set['set_id']]['values']['value_'.$value['value_id']]['price_mod'] = $value['price_mod']; + $all_sets[$set['set_id']]['values']['value_'.$value['value_id']]['weight_prefix'] = $value['weight_prefix']; + $all_sets[$set['set_id']]['values']['value_'.$value['value_id']]['weight_mod'] = $value['weight_mod']; + } + } + + if ($print) { // print + // not sure about print yet + } elseif ($form) { // form + if (isset($_REQUEST[$set['set_id']])) { + $match = 'options['.$set['set_id'].']'; + } else { + $match =null; + } + if ($o_set['type'] == 1) { // list + $all_sets .= '<strong>' . $o_set['title'] . '</strong><br />'; + $all_sets .= PHPWS_Form::formSelect('options['.$set['set_id'].']', $choices[$set['set_id']]) . '<br /><br />'; + } elseif ($o_set['type'] == 2) { // buttons + $all_sets .= '<strong>' . $o_set['title'] . '</strong><br />'; + $all_sets .= $buttons . '<br />'; + } elseif ($o_set['type'] == 3) { // checkboxes + $all_sets .= '<strong>' . $o_set['title'] . '</strong><br />'; + $all_sets .= $boxes . '<br />'; + } + } else { // array + $all_sets[$set['set_id']]['id'] = $o_set['id']; + $all_sets[$set['set_id']]['type'] = $o_set['type']; + $all_sets[$set['set_id']]['title'] = $o_set['title']; + } + + } + + // print_r($all_sets); exit; + return $all_sets; + } + + + public function getQtyAttributes() + { + $db = new PHPWS_DB('vshop_attributes'); + $db->addWhere('item_id', $this->id); + $qty = $db->count(); + return $qty; + } + + public function view() { *************** *** 277,281 **** --- 400,410 ---- } + // PHPWS_Core::initModClass('vshop', 'vShop_Cart.php'); + // $cart = vShop_Cart::CreateInstance(); + // $cart_data = $cart->GetCart(); + // print_r($cart_data); + $key = new Key($this->key_id); + $options = $this->getQtyAttributes(); if (!$key->allowView()) { *************** *** 283,289 **** --- 412,431 ---- } + if ($options > 0) { + $form = new PHPWS_Form('vshop_addItem'); + $form->addHidden('module', 'vshop'); + $form->addHidden('uop', 'addto_cart'); + $form->addHidden('item', $this->id); + $form->addHidden('dept', $this->dept_id); + $form->addSubmit(dgettext('vshop', 'Add to cart')); + $tpl = $form->getTemplate(); + } + Layout::addPageTitle($this->getTitle()); $tpl['ITEM_LINKS'] = $this->links(); $tpl['TITLE'] = $this->getTitle(true); + if ($options > 0) { + $tpl['PRICE_NOTE'] = dgettext('vshop', 'From'); + } $tpl['PRICE'] = $this->getPrice(true); if (PHPWS_Settings::get('vshop', 'use_inventory')) { *************** *** 298,303 **** $tpl['FILE'] = $this->getFile(); ! $key->flag(); return PHPWS_Template::process($tpl, 'vshop', 'view_item.tpl'); } --- 440,448 ---- $tpl['FILE'] = $this->getFile(); ! if ($options > 0) { ! $tpl['OPTIONS'] = $this->getOptionSets(); ! } + $key->flag(); return PHPWS_Template::process($tpl, 'vshop', 'view_item.tpl'); } *************** *** 308,312 **** $links = array(); ! $links[] = $this->addLink(true) . ' ' . $this->addLink(); if (Current_User::allow('vshop', 'edit_items')) { $vars['dept_id'] = $this->dept_id; --- 453,461 ---- $links = array(); ! if ($this->getQtyAttributes() < 1) { ! $links[] = $this->addLink(true) . ' ' . $this->addLink(); ! } //else { ! // $links[] = sprintf('<a href="%s">', $this->viewLink(true)) . dgettext('vshop', 'Choose Options') . '</a>'; ! // } if (Current_User::allow('vshop', 'edit_items')) { $vars['dept_id'] = $this->dept_id; *************** *** 384,388 **** $links = array(); ! $links[] = $this->addLink(true) . ' ' . $this->addLink(); if (Current_User::allow('vshop', 'edit_items')) { --- 533,541 ---- $links = array(); ! if ($this->getQtyAttributes() < 1) { ! $links[] = $this->addLink(true) . ' ' . $this->addLink(); ! } else { ! $links[] = sprintf('<a href="%s">', $this->viewLink(true)) . dgettext('vshop', 'Choose Options') . '</a>'; ! } if (Current_User::allow('vshop', 'edit_items')) { Index: vShop.php =================================================================== RCS file: /cvsroot/phpwebsite-comm/modules/vshop/class/vShop.php,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** vShop.php 5 Dec 2008 15:22:52 -0000 1.5 --- vShop.php 4 Mar 2009 14:39:49 -0000 1.6 *************** *** 68,71 **** --- 68,76 ---- case 'post_option_value': case 'delete_option_value': + // case 'view_attribute': + // case 'new_attribute': + // case 'edit_attribute': + // case 'post_attribute': + // case 'delete_attribute': PHPWS_Core::initModClass('vshop', 'vShop_Forms.php'); *************** *** 158,162 **** } else { $this->forwardMessage(dgettext('vshop', 'Item saved successfully.')); ! PHPWS_Core::reroute('index.php?module=vshop&dept='.$this->item->dept_id); } } else { --- 163,168 ---- } else { $this->forwardMessage(dgettext('vshop', 'Item saved successfully.')); ! // old PHPWS_Core::reroute('index.php?module=vshop&dept='.$this->item->dept_id); ! PHPWS_Core::reroute('index.php?module=vshop&aop=menu&tab=list_items&dept='.$this->item->dept_id); // new from wendall } } else { *************** *** 315,318 **** --- 321,371 ---- + case 'view_attribute': + // $settingsPanel->setCurrentTab('option_values'); + $this->loadAttribute(); + $this->title = $this->attribute->getTitle(true); + $this->content = $this->attribute->view(); + break; + + case 'new_attribute': + case 'edit_attribute': + // $settingsPanel->setCurrentTab('option_values'); + if (!Current_User::authorized('vshop', 'edit_items')) { + Current_User::disallow(); + } + // $this->loadAttribute(); + $this->loadForm('edit_attribute'); + break; + + case 'post_attribute': + // $settingsPanel->setCurrentTab('option_values'); + if (!Current_User::authorized('vshop', 'edit_items')) { + Current_User::disallow(); + } + if ($this->postAttribute()) { + if (PHPWS_Error::logIfError($this->attribute->save())) { + $this->forwardMessage(dgettext('vshop', 'Error occurred when saving attribute.')); + PHPWS_Core::reroute('index.php?module=vshop&aop=menu&tab=option_values'); // CHECK !!! + } else { + $this->forwardMessage(dgettext('vshop', 'Attribute saved successfully.')); + PHPWS_Core::reroute('index.php?module=vshop&aop=menu&tab=option_values'); // CHECK !!! + } + } else { + $this->loadForm('edit_attribute'); + } + break; + + case 'delete_attribute': + // $settingsPanel->setCurrentTab('option_values'); + if (!Current_User::authorized('vshop', 'edit_items')) { + Current_User::disallow(); + } + $this->loadAttribute(); + $this->attribute->delete(); + $this->message = dgettext('vshop', 'Attribute deleted.'); + $this->loadForm('attributes'); // CHECK !!! + break; + + case 'post_settings': $settingsPanel->setCurrentTab('settings'); *************** *** 447,450 **** --- 500,508 ---- case 'post_option_value': case 'delete_option_value': + // case 'view_attribute': + // case 'new_attribute': + // case 'edit_attribute': + // case 'post_attribute': + // case 'delete_attribute': $settingsPanel->setContent($this->content); $this->content = $settingsPanel->display(); *************** *** 549,554 **** $new_qty = $qty_incart + $qty; } ! if (PHPWS_Settings::get('vshop', 'use_inventory') && $new_qty <= $this->item->stock) { ! $cart->addItems($this->item->id, null, $qty); $this->forwardMessage(sprintf(dgettext('vshop', '%s successfully added to your cart.'), $this->item->getTitle(true))); } else { --- 607,629 ---- $new_qty = $qty_incart + $qty; } ! // old if (PHPWS_Settings::get('vshop', 'use_inventory') && $new_qty <= $this->item->stock) { ! if ((PHPWS_Settings::get('vshop', 'use_inventory') && $new_qty <= $this->item->stock) || (!PHPWS_Settings::get('vshop', 'use_inventory'))) { // fixed thanks wendall ! print_r($_REQUEST); exit; // TEMP ! /* need to test for options here and if there are, build data array for them */ ! if (isset($_REQUEST['options'])) { ! // $options = $_REQUEST['options']; ! PHPWS_Core::initModClass('vshop', 'vShop_Option_set.php'); ! PHPWS_Core::initModClass('vshop', 'vShop_Attribute.php'); ! /* loop through the options */ ! foreach ($_REQUEST['options'] as $o_set) { ! /* if the option is an array - checkboxes */ ! if (is_array($o_set)) { ! } else { ! } ! } ! } else { ! $options = null; ! } ! $cart->addItems($this->item->id, $options, $qty); $this->forwardMessage(sprintf(dgettext('vshop', '%s successfully added to your cart.'), $this->item->getTitle(true))); } else { *************** *** 843,846 **** --- 918,951 ---- + public function loadAttribute($id=0) + { + PHPWS_Core::initModClass('vshop', 'vShop_Attribute.php'); + + if ($id) { + $this->attribute = new vShop_Attribute($id); + } elseif (isset($_REQUEST['attribute_id'])) { + $this->attribute = new vShop_Attribute($_REQUEST['attribute_id']); + // } elseif (isset($_REQUEST['id'])) { + // $this->attribute = new vShop_Attribute($_REQUEST['id']); + } elseif (isset($_REQUEST['attribute'])) { + $this->attribute = new vShop_Attribute($_REQUEST['attribute']); + } else { + $this->attribute = new vShop_Attribute; + } + + if (empty($this->item)) { + if (isset($this->attribute->item_id)) { + $this->loadItem($this->attribute->item_id); + } elseif (isset($_REQUEST['item_id'])) { + $this->loadItem($_REQUEST['item_id']); + $this->attribute->item_id = $_REQUEST['item_id']; + } else { + $this->loadItem(); + $this->attribute->item_id = $this->item->id; + } + } + } + + public function loadOrder($id=0) { *************** *** 939,943 **** } ! if (!empty($_POST['price']) ) { $this->item->setPrice($_POST['price']); } --- 1044,1049 ---- } ! // old if (!empty($_POST['price'])) { ! if (is_numeric($_POST['price'])) { $this->item->setPrice($_POST['price']); } *************** *** 947,959 **** $this->item->setTaxable(0) ; ! if (!empty($_POST['stock']) ) { $this->item->setStock((int)$_POST['stock']); } ! if (!empty($_POST['weight']) ) { $this->item->setWeight($_POST['weight']); } ! if (!empty($_POST['shipping']) ) { $this->item->setShipping($_POST['shipping']); } --- 1053,1068 ---- $this->item->setTaxable(0) ; ! // old if (!empty($_POST['stock'])) { ! if (is_int($_POST['stock'])) { $this->item->setStock((int)$_POST['stock']); } ! // old if (!empty($_POST['weight'])) { ! if (is_numeric($_POST['weight'])) { $this->item->setWeight($_POST['weight']); } ! // old if (!empty($_POST['shipping'])) { ! if (is_numeric($_POST['shipping'])) { $this->item->setShipping($_POST['shipping']); } *************** *** 1056,1059 **** --- 1165,1206 ---- + public function postAttribute() + { + $this->loadAttribute(); + //print_r($_POST); exit; + + if (isset($_POST['set_id'])) { + $this->attribute->setSet_id($_POST['set_id']); + } else { + PHPWS_Core::initModClass('vshop', 'vShop_Option_value.php'); + $value = new vShop_Option_value($_POST['value_id']); + $this->attribute->setSet_id($value->set_id); + } + $this->attribute->setValue_id($_POST['value_id']); + $this->attribute->setItem_id($_POST['item_id']); + if (!empty($_POST['price_mod']) ) { + $this->attribute->setPrice_mod($_POST['price_mod']); + } else { + $this->attribute->setPrice_mod(0); + } + $this->attribute->setPrice_prefix($_POST['price_prefix']); + if (!empty($_POST['weight_mod']) ) { + $this->attribute->setWeight_mod($_POST['weight_mod']); + } else { + $this->attribute->setWeight_mod(0); + } + $this->attribute->setWeight_prefix($_POST['weight_prefix']); + + if (isset($errors)) { + $this->message = implode('<br />', $errors); + $this->loadForm('edit_attribute'); // CHECK !!! + return false; + } else { + return true; + } + + } + + public function postSettings() { *************** *** 1340,1348 **** } /* loop through the items in the cart */ foreach ($cart_data as $id=>$val) { ! $qty = $cart_data[$id]['count']; $item = new vShop_Item($id); $subtotal = $item->price * $qty; $item_tax = 0.00; --- 1487,1499 ---- } + //print_r($cart_data); exit; /* loop through the items in the cart */ foreach ($cart_data as $id=>$val) { ! print_r($cart_data[$id]['data']->_itemData); //exit; // TEMP $qty = $cart_data[$id]['count']; + // $opts = $cart_data[$id]['']; $item = new vShop_Item($id); + // if () { + // } $subtotal = $item->price * $qty; $item_tax = 0.00; *************** *** 1430,1434 **** } ! // print_r($order_array); exit; $this->order->order_array = $order_array; $this->order->order_date = mktime(); --- 1581,1585 ---- } ! print_r($order_array); exit; $this->order->order_array = $order_array; $this->order->order_date = mktime(); *************** *** 1527,1531 **** public function navLinks() { ! $links = null; if (!PHPWS_Settings::get('vshop', 'use_breadcrumb')) { if (vShop::countDepts() !== 1) { --- 1678,1683 ---- public function navLinks() { ! // $links = null; ! $links = array(); if (!PHPWS_Settings::get('vshop', 'use_breadcrumb')) { if (vShop::countDepts() !== 1) { --- NEW FILE: vShop_Attribute.php --- <?php /** * vshop - phpwebsite module * * See docs/AUTHORS and docs/COPYRIGHT for relevant info. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @version $Id: vShop_Attribute.php,v 1.1 2009/03/04 14:39:52 verdonv Exp $ * @author Verdon Vaillancourt <verdonv at users dot sourceforge dot net> */ class vShop_Attribute { public $id = 0; public $set_id = null; public $value_id = null; public $item_id = null; public $price_mod = 0; public $price_prefix = null; public $weight_mod = 0; public $weight_prefix = null; public $_error = null; public function __construct($id=0) { if (!$id) { return; } $this->id = (int)$id; $this->init(); } public function init() { $db = new PHPWS_DB('vshop_attributes'); $result = $db->loadObject($this); if (PEAR::isError($result)) { $this->_error = & $result; $this->id = 0; } elseif (!$result) { $this->id = 0; } } public function setSet_id($set_id) { $this->set_id = (int)$set_id; } public function setValue_id($value_id) { $this->value_id = (int)$value_id; } public function setItem_id($item_id) { $this->item_id = (int)$item_id; } public function setPrice_mod($price_mod) { $this->price_mod = $price_mod; } public function setPrice_prefix($price_prefix) { $this->price_prefix = $price_prefix; } public function setWeight_mod($weight_mod) { $this->weight_mod = $weight_mod; } public function setWeight_prefix($weight_prefix) { $this->weight_prefix = $weight_prefix; } public function getTitle($print=false) { if (empty($this->set_id) || empty($this->value_id)) { return null; } if ($print) { PHPWS_Core::initModClass('vshop', 'vShop_Option_set.php'); $set = new vShop_Option_set($this->set_id); PHPWS_Core::initModClass('vshop', 'vShop_Option_value.php'); $value = new vShop_Option_value($this->value_id); return $set->getTitle(true) . ' : ' . $value->getTitle(true); } else { return $this->set_id . ':' . $this->value_id; } } public function getSet($print=false) { if (empty($this->set_id)) { return null; } if ($print) { PHPWS_Core::initModClass('vshop', 'vShop_Option_set.php'); $set = new vShop_Option_set($this->set_id); return $set->getTitle(true); } else { return $this->set_id; } } public function getValue($print=false) { if (empty($this->value_id)) { return null; } if ($print) { PHPWS_Core::initModClass('vshop', 'vShop_Option_value.php'); $value = new vShop_Option_value($this->value_id); return $value->getTitle(true); } else { return $this->value_id; } } public function getPrice_mod($print=false) { if (empty($this->price_mod)) { return null; } if ($print) { if (PHPWS_Settings::get('vshop', 'curr_symbol_pos') == 1) { $price_mod = PHPWS_Settings::get('vshop', 'currency_symbol') . number_format($this->price_mod, 2, '.', ','); if (PHPWS_Settings::get('vshop', 'display_currency')) { $price_mod .= ' ' . PHPWS_Settings::get('vshop', 'currency'); } } else { $price_mod = number_format($this->price_mod, 2, '.', ',') . PHPWS_Settings::get('vshop', 'currency_symbol'); if (PHPWS_Settings::get('vshop', 'display_currency')) { $price_mod .= ' ' . PHPWS_Settings::get('vshop', 'currency'); } } return $price_mod; } else { return $this->price_mod; } } public function getWeight_mod($print=false) { if (empty($this->weight_mod)) { return null; } if ($print) { return $this->weight_mod . PHPWS_Settings::get('vshop', 'weight_unit'); } else { return $this->weight_mod; } } public function view() { if (!$this->id) { PHPWS_Core::errorPage(404); } $tpl['ATTRIBUTE_LINKS'] = $this->links(); $tpl['TITLE'] = $this->getTitle(true); return PHPWS_Template::process($tpl, 'vshop', 'view_attribute.tpl'); } public function links() { $links = array(); if (Current_User::allow('vshop', 'edit_items')) { $vars['attribute_id'] = $this->id; $vars['aop'] = 'edit_attribute'; $links[] = PHPWS_Text::secureLink(dgettext('vshop', 'Edit attribute'), 'vshop', $vars); } if($links) return implode(' | ', $links); } public function delete() { if (!$this->id) { return; } $db = new PHPWS_DB('vshop_attributes'); $db->addWhere('id', $this->id); PHPWS_Error::logIfError($db->delete()); } public function rowTag() { $vars['attribute_id'] = $this->id; $links = array(); if (Current_User::allow('vshop', 'edit_items')) { $vars['aop'] = 'edit_attribute'; $links[] = PHPWS_Text::secureLink(dgettext('vshop', 'Edit'), 'vshop', $vars); $vars['aop'] = 'delete_attribute'; $js['ADDRESS'] = PHPWS_Text::linkAddress('vshop', $vars, true); $js['QUESTION'] = sprintf(dgettext('vshop', 'Are you sure you want to delete the attribute %s?'), $this->getTitle()); $js['LINK'] = dgettext('vshop', 'Delete'); $links[] = javascript('confirm', $js); } $tpl['TITLE'] = $this->viewLink(); if($links) $tpl['ACTION'] = implode(' | ', $links); return $tpl; } public function viewTpl() { $vars['attribute_id'] = $this->id; $links = array(); if (Current_User::allow('vshop', 'edit_items')) { $vars['aop'] = 'edit_attribute'; $links[] = PHPWS_Text::secureLink(dgettext('vshop', 'Edit'), 'vshop', $vars); } if (Current_User::allow('vshop', 'edit_items')) { $vars['aop'] = 'delete_attribute'; $js['ADDRESS'] = PHPWS_Text::linkAddress('vshop', $vars, true); $js['QUESTION'] = sprintf(dgettext('vshop', 'Are you sure you want to delete the attribute %s?'), $this->getTitle(true)); $js['LINK'] = dgettext('vshop', 'Delete'); $links[] = javascript('confirm', $js); } // $tpl['ATTRIBUTE_TITLE'] = $this->getTitle(true); $tpl['ATTRIBUTE_SET'] = $this->getSet(true); $tpl['ATTRIBUTE_VALUE'] = $this->getValue(true); $tpl['ATTRIBUTE_PRICE_PREFIX'] = $this->price_prefix; $tpl['ATTRIBUTE_PRICE_MOD'] = $this->getPrice_mod(true); $tpl['ATTRIBUTE_WEIGHT_PREFIX'] = $this->weight_prefix; $tpl['ATTRIBUTE_WEIGHT_MOD'] = $this->getWeight_mod(true); if($links) $tpl['ATTRIBUTE_LINKS'] = implode(' | ', $links); return $tpl; } public function save() { $db = new PHPWS_DB('vshop_attributes'); $result = $db->saveObject($this); if (PEAR::isError($result)) { return $result; } } public function viewLink() { $vars['aop'] = 'view_attribute'; $vars['attribute'] = $this->id; return PHPWS_Text::moduleLink(dgettext('vshop', $this->title), 'vshop', $vars); } } ?> Index: vShop_Forms.php =================================================================== RCS file: /cvsroot/phpwebsite-comm/modules/vshop/class/vShop_Forms.php,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** vShop_Forms.php 5 Dec 2008 15:22:52 -0000 1.5 --- vShop_Forms.php 4 Mar 2009 14:39:53 -0000 1.6 *************** *** 103,106 **** --- 103,114 ---- break; + case 'new_attribute': + case 'edit_attribute': + if (empty($this->vshop->attribute)) { + $this->vshop->loadAttribute(); + } + $this->editAttribute(); + break; + case 'edit_order': if (empty($this->vshop->order)) { *************** *** 534,541 **** --- 542,585 ---- + $tpl['ATTRIBUTES_LABEL'] = dgettext('vshop', 'Item options'); + if ($this->getQtyValues() > 0) { + $tpl['ADD_ATTRIBUTE_LINK'] = PHPWS_Text::secureLink(dgettext('vshop', 'Add Attribute'), 'vshop', array('aop'=>'new_attribute', 'item_id'=>$item->id)); + } else { + $tpl['ADD_ATTRIBUTE_LINK'] = dgettext('vshop', 'Sorry, but you must define option sets and values before you may add an attribute to an item.'); + } + + $attributes = $item->getAllAttributes(); + if (PHPWS_Error::logIfError($attributes)) { + $this->vshop->content = dgettext('vshop', 'An error occurred when accessing this items\'s attributes.'); + return; + } + + if ($attributes) { + $tpl['ATTRIBUTE_SET_LABEL'] = dgettext('vshop', 'Set'); + $tpl['ATTRIBUTE_VALUE_LABEL'] = dgettext('vshop', 'Value'); + $tpl['ATTRIBUTE_PRICE_LABEL'] = dgettext('vshop', 'Price mod'); + $tpl['ATTRIBUTE_WEIGHT_LABEL'] = dgettext('vshop', 'Weight mod'); + foreach ($attributes as $attribute) { + $tpl['attributes'][] = $attribute->viewTpl(); + } + } else { + $tpl['NONE'] = dgettext('vshop', 'This item has no options'); + } + + + + $this->vshop->content = PHPWS_Template::process($tpl, 'vshop', 'edit_item.tpl'); } + public function getQtyValues() + { + $db = new PHPWS_DB('vshop_option_values'); + $qty = $db->count(); + return $qty; + } + + public function editTax() { *************** *** 660,663 **** --- 704,778 ---- + public function editAttribute() + { + $form = new PHPWS_Form; + $attribute = & $this->vshop->attribute; + $item = & $this->vshop->item; + //print_r($item); exit; + + $form->addHidden('module', 'vshop'); + $form->addHidden('aop', 'post_attribute'); + if ($attribute->id) { + $this->vshop->title = dgettext('vshop', 'Update attribute'); + $form->addHidden('attribute_id', $attribute->id); + $form->addHidden('set_id', $attribute->set_id); + $form->addSubmit(dgettext('vshop', 'Update')); + } else { + $this->vshop->title = dgettext('vshop', 'Add new attribute'); + $form->addSubmit(dgettext('vshop', 'Add')); + } + $form->addHidden('item_id', $item->id); + + PHPWS_Core::initModClass('vshop', 'vShop_Option_value.php'); + $db = new PHPWS_DB('vshop_option_values'); + $db->addColumn('id'); + $db->addColumn('set_id'); + $db->addColumn('title'); + $db->addColumn('vshop_option_sets.title', null, 'setname'); + $db->addOrder('vshop_option_sets.title asc'); + $db->addOrder('sort asc'); + $db->addOrder('title asc'); + $db->addWhere('vshop_option_sets.id', 'vshop_option_values.set_id'); + // $db->setTestMode(); + $result = $db->select(); + if ($result) { + foreach ($result as $value) { + $name = $value['setname'] . ' : ' . $value['title']; + $choices[$value['id']] = PHPWS_Text::parseOutput($name); + } + $form->addSelect('value_id', $choices); + $form->setLabel('value_id', dgettext('vshop', 'Option value')); + $form->setMatch('value_id', $attribute->value_id); + } + + $choices = array('+'=>'+','-'=>'-'); + $form->addSelect('price_prefix', $choices); + $form->setLabel('price_prefix', dgettext('vshop', 'Price prefix')); + $form->setMatch('price_prefix', $attribute->price_prefix); + + $form->addText('price_mod', $attribute->price_mod); + $form->setSize('price_mod', 10); + $form->setMaxSize('price_mod', 20); + // $form->setRequired('price_mod'); + $form->setLabel('price_mod', dgettext('vshop', 'Price modifier (x.xx)')); + + $choices = array('+'=>'+','-'=>'-'); + $form->addSelect('weight_prefix', $choices); + $form->setLabel('weight_prefix', dgettext('vshop', 'Weight prefix')); + $form->setMatch('weight_prefix', $attribute->weight_prefix); + + $form->addText('weight_mod', $attribute->weight_mod); + $form->setSize('weight_mod', 5); + $form->setMaxSize('weight_mod', 5); + // $form->setRequired('weight_mod'); + $form->setLabel('weight_mod', sprintf(dgettext('vshop', 'Weight modifier (%s)'), PHPWS_Settings::get('vshop', 'weight_unit'))); + + $tpl = $form->getTemplate(); + $tpl['INFO_LABEL'] = dgettext('vshop', 'Attribute details'); + + $this->vshop->content = PHPWS_Template::process($tpl, 'vshop', 'edit_attribute.tpl'); + } + + public function editOrder() { |