当前位置: 首页>>代码示例>>PHP>>正文


PHP Attribute::getById方法代码示例

本文整理汇总了PHP中Attribute::getById方法的典型用法代码示例。如果您正苦于以下问题:PHP Attribute::getById方法的具体用法?PHP Attribute::getById怎么用?PHP Attribute::getById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Attribute的用法示例。


在下文中一共展示了Attribute::getById方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getByOptionId

 /**
  * Returns a new Attribute queried by one of its option IDs from
  * the database.
  * @param   integer     $option_id    The option ID
  * @static
  */
 static function getByOptionId($option_id)
 {
     // Get the associated Attribute ID
     $attribute_id = Attribute::getIdByOptionId($option_id);
     return Attribute::getById($attribute_id);
 }
开发者ID:nahakiole,项目名称:cloudrexx,代码行数:12,代码来源:Attribute.class.php

示例2: getAsStrings

 /**
  * Returns an array of two HTML representations of the Attributes and
  * their respective options specified by the array given
  *
  * One of these representation may be used anywhere the matching Product
  * is viewed.  The first (at index 0) is the long form best used in the
  * cart view, the second (at index 1) is suitable for the JSCart in the
  * sidebar.
  * Attributes with an empty list of option IDs will not be included in
  * the string produced.  Invalid IDs are silently skipped.
  * Note that the format of the string can be easily customized by editing
  * the following language entries:
  *  TXT_SHOP_OPTION_LONG_FORMAT
  *  TXT_SHOP_OPTION_LONG_FORMAT_JOINER
  *  TXT_SHOP_ATTRIBUTE_LONG_FORMAT
  *  TXT_SHOP_ATTRIBUTE_LONG_FORMAT_JOINER
  *  TXT_SHOP_OPTION_CART_FORMAT
  *  TXT_SHOP_OPTION_CART_FORMAT_JOINER
  *  TXT_SHOP_ATTRIBUTE_CART_FORMAT
  *  TXT_SHOP_ATTRIBUTE_CART_FORMAT_JOINER
  * The array parameter must have the form
  *  array(
  *    Attribute ID => array(
  *      option ID,
  *      [...]
  *    ),
  *    [...],
  *  )
  * @global  array   $_ARRAYLANG
  * @param   array   $arrAttributesOptions   The array of Attribute and
  *                                          option IDs
  * @param   float   $options_price          The sum of all option prices,
  *                                          by reference
  * @return  array                           The array of two HTML
  *                                          representations of
  *                                          the Attributes and options
  *                                          present in the parameter array
  */
 static function getAsStrings($arrAttributesOptions, &$options_price = NULL)
 {
     global $_ARRAYLANG;
     //DBG::log("Attributes::getAsStrings(".var_export($arrAttributesOptions, true).", $options_price)");
     $options_price = 0;
     if (!is_array($arrAttributesOptions) || empty($arrAttributesOptions)) {
         return array('', '');
     }
     $attributes_long = $attributes_cart = array();
     foreach ($arrAttributesOptions as $attribute_id => $arrOptionIds) {
         //DBG::log("Attributes::getAsStrings(): Attribute ID $attribute_id");
         if (empty($arrOptionIds)) {
             continue;
         }
         $objAttribute = Attribute::getById($attribute_id);
         if (!$objAttribute) {
             continue;
         }
         //DBG::log("Attributes::getAsStrings(): Attribute ".var_export($objAttribute, true));
         $options_long = $options_cart = array();
         $arrOptions = $objAttribute->getOptionArray();
         foreach ($arrOptionIds as $option_id) {
             //DBG::log("Attributes::getAsStrings(): Option ID $option_id");
             $option_name = '';
             // Valid indices are: 'value', 'price', 'order'
             $option_price = $arrOptions[$option_id]['price'];
             // Note that this *MUST NOT* test for is_integer()
             // (which $option_id isn't -- it's either an arbitrary
             // string, or one that represents a positive integer),
             // but for a *string matching a valid ID*.
             // intval() doesn't do the job properly, as it also
             // converts "1 but true" to 1.
             // A good match would be done by is_numeric(); however,
             // this would also accept floats and scientific
             // notation...
             if (preg_match('/^[1-9][0-9]*$/', $option_id) && in_array($objAttribute->getType(), array(Attribute::TYPE_MENU_OPTIONAL, Attribute::TYPE_MENU_MANDATORY, Attribute::TYPE_RADIOBUTTON, Attribute::TYPE_CHECKBOX))) {
                 $option_name = $arrOptions[$option_id]['value'];
             } else {
                 $option_name = ShopLibrary::stripUniqidFromFilename($option_id);
                 $path = Order::UPLOAD_FOLDER . $option_id;
                 if ($option_name != $option_id && file_exists($path)) {
                     $option_name = \Html::getLink('/' . $path, $option_name, 'uploadimage');
                 }
             }
             $options_long[] = sprintf($_ARRAYLANG['TXT_SHOP_OPTION_LONG_FORMAT'], $option_name, $option_price, Currency::getActiveCurrencyCode(), Currency::getActiveCurrencySymbol());
             $options_cart[] = sprintf($_ARRAYLANG['TXT_SHOP_OPTION_CART_FORMAT'], $option_name, $option_price, Currency::getActiveCurrencyCode(), Currency::getActiveCurrencySymbol());
             $options_price += $option_price;
             //DBG::log("Attributes::getAsStrings(): Price + $option_price = $options_price");
         }
         if ($options_long) {
             $options_long = join($_ARRAYLANG['TXT_SHOP_OPTION_LONG_FORMAT_JOINER'], $options_long);
             $attributes_long[] = sprintf($_ARRAYLANG['TXT_SHOP_ATTRIBUTE_LONG_FORMAT'], $objAttribute->getName(), $options_long);
             $options_cart = join($_ARRAYLANG['TXT_SHOP_OPTION_CART_FORMAT_JOINER'], $options_cart);
             $attributes_cart[] = sprintf($_ARRAYLANG['TXT_SHOP_ATTRIBUTE_CART_FORMAT'], $objAttribute->getName(), $options_cart);
         }
     }
     if ($attributes_long) {
         $attributes_long = join($_ARRAYLANG['TXT_SHOP_ATTRIBUTE_LONG_FORMAT_JOINER'], $attributes_long);
         $attributes_cart = join($_ARRAYLANG['TXT_SHOP_ATTRIBUTE_CART_FORMAT_JOINER'], $attributes_cart);
     }
     return array($attributes_long, $attributes_cart);
 }
开发者ID:Niggu,项目名称:cloudrexx,代码行数:100,代码来源:Attributes.class.php

示例3: insertAttribute

 /**
  * Add the option IDs of the given Attribute ID to the Order item
  *
  * Will add error messages using {@see Message::error()}, if any.
  * The $arrOptionIds array must have the form
  *  array(attribute_id => array(option_id, ...))
  * @param   integer   $item_id        The Order item ID
  * @param   integer   $attribute_id   The Attribute ID
  * @param   array     $arrOptionIds   The array of option IDs
  * @return  boolean                   True on success, false otherwise
  * @static
  */
 static function insertAttribute($item_id, $attribute_id, $arrOptionIds)
 {
     global $objDatabase, $_ARRAYLANG;
     $objAttribute = Attribute::getById($attribute_id);
     if (!$objAttribute) {
         return \Message::error($_ARRAYLANG['TXT_SHOP_ERROR_INVALID_ATTRIBUTE_ID']);
     }
     $name = $objAttribute->getName();
     $_arrOptions = Attributes::getOptionArrayByAttributeId($attribute_id);
     foreach ($arrOptionIds as $option_id) {
         $arrOption = null;
         if ($objAttribute->getType() >= Attribute::TYPE_TEXT_OPTIONAL) {
             // There is exactly one option record for these
             // types.  Use that and overwrite the empty name with
             // the text or file name.
             $arrOption = current($_arrOptions);
             $arrOption['value'] = $option_id;
         } else {
             // Use the option record for the option ID given
             $arrOption = $_arrOptions[$option_id];
         }
         if (!is_array($arrOption)) {
             \Message::error($_ARRAYLANG['TXT_SHOP_ERROR_INVALID_OPTION_ID']);
             continue;
         }
         $query = "\n                INSERT INTO `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_order_attributes`\n                   SET `item_id`={$item_id},\n                       `attribute_name`='" . addslashes($name) . "',\n                       `option_name`='" . addslashes($arrOption['value']) . "',\n                       `price`='" . $arrOption['price'] . "'";
         $objResult = $objDatabase->Execute($query);
         if (!$objResult) {
             return \Message::error($_ARRAYLANG['TXT_ERROR_INSERTING_ORDER_ITEM_ATTRIBUTE']);
         }
     }
     return true;
 }
开发者ID:Niggu,项目名称:cloudrexx,代码行数:45,代码来源:Order.class.php

示例4: add_product


//.........这里部分代码省略.........
             foreach ($arrNewProduct['options'] as $attribute_id => $value) {
                 if (empty($value)) {
                     //DBG::log("Cart::add_product(): New: Empty option value for Attribute ID $attribute_id");
                     continue;
                 }
                 if (isset($arrProduct['options'][$attribute_id]) && is_array($arrProduct['options'][$attribute_id])) {
                     $arrPostValues = array();
                     if (is_array($value)) {
                         $arrPostValues = array_values($value);
                     } else {
                         array_push($arrPostValues, $value);
                     }
                     if ($arrPostValues !== $arrProduct['options'][$attribute_id]) {
                         //DBG::log("Cart::add_product(): Different options: New: ".var_export($arrPostValues, true).", Old: ".var_export($arrProduct['options'][$attribute_id], true));
                         continue 2;
                     }
                 } else {
                     if (!isset($arrProduct['options'][$attribute_id][$value])) {
                         //DBG::log("Cart::add_product(): Missing option");
                         continue 2;
                     }
                 }
             }
             // All options identical
             $new = false;
             //DBG::log("Cart::add_product(): Identical options as Cart ID $cart_id: New: ".var_export($arrNewProduct['options'], true).", Old: ".var_export($arrProduct['options'], true));
             break;
         }
         //DBG::log("Cart::add_product(): No match!");
     }
     //DBG::log("Cart::add_product(): Comparing done, cart ID $cart_id");
     if ($new) {
         if (isset($old_cart_id)) {
             //DBG::log("Cart::add_product(): New Product: Replacing cart ID with old $old_cart_id");
             $cart_id = $old_cart_id;
         } else {
             //DBG::log("Cart::add_product(): New Product: Creating new cart ID");
             // TODO: True? // $arrNewProduct['id'] may be undefined!
             $arrProduct = array('id' => $arrNewProduct['id'], 'quantity' => $quantity);
             array_push($products, $arrProduct);
             $arrKeys = array_keys($products);
             $cart_id = $arrKeys[count($arrKeys) - 1];
         }
     } else {
         if (isset($old_cart_id)) {
             //DBG::log("Cart::add_product(): Old Product: Have cart ID...");
             if ($old_cart_id != $cart_id) {
                 //DBG::log("Cart::add_product(): Old Product: Merging");
                 $products[$cart_id]['quantity'] += $products[$old_cart_id]['quantity'];
                 unset($products[$old_cart_id]);
             } else {
                 //DBG::log("Cart::add_product(): Old Product: Same cart ID, not merged!");
             }
         } else {
             //DBG::log("Cart::add_product(): Old Product: Adding quantity $quantity to {$products[$cart_id]['quantity']} in cart ID $cart_id (old ID $old_cart_id)");
             $products[$cart_id]['quantity'] += $quantity;
             //DBG::log("Cart::add_product(): Old Product: Updated quantity to {$_SESSION['shop']['cart']['items'][$cart_id]['quantity']}");
         }
     }
     // Add options
     // TODO: I suspect that this could be completely skipped when $new === false!?
     $products[$cart_id]['options'] = array();
     if (isset($arrNewProduct['options']) && count($arrNewProduct['options']) > 0) {
         //DBG::log("Cart::add_product(): Adding options: New: ".var_export($arrNewProduct['options'], true));
         foreach ($arrNewProduct['options'] as $attribute_id => $option_id) {
             $attribute_id = intval($attribute_id);
             // Get Attribute
             $objAttribute = Attribute::getById($attribute_id);
             if (!$objAttribute) {
                 continue;
             }
             $type = $objAttribute->getType();
             if ($type == Attribute::TYPE_TEXT_OPTIONAL || $type == Attribute::TYPE_TEXT_MANDATORY) {
                 if ($option_id == '') {
                     continue;
                 }
             }
             if ($type == Attribute::TYPE_UPLOAD_OPTIONAL || $type == Attribute::TYPE_UPLOAD_MANDATORY) {
                 $filename = $arrNewProduct['options'][$attribute_id];
                 $option_id = Shop::uploadFile($filename);
                 if ($option_id == '') {
                     continue;
                 }
             }
             if (!isset($products[$cart_id]['options'][$attribute_id])) {
                 $products[$cart_id]['options'][$attribute_id] = array();
             }
             if (is_array($option_id) && count($option_id)) {
                 foreach ($option_id as $id) {
                     array_push($products[$cart_id]['options'][$attribute_id], $id);
                 }
             } elseif (!empty($option_id)) {
                 array_push($products[$cart_id]['options'][$attribute_id], contrexx_input2raw($option_id));
             }
         }
     }
     $_SESSION['shop']['cart']['items'] = $products;
     //DBG::log("Cart::add_product(): New options: ".var_export($products[$cart_id]['options'], true));
     //DBG::log("Cart::add_product(): Leaving");
 }
开发者ID:Niggu,项目名称:cloudrexx,代码行数:101,代码来源:Cart.class.php

示例5: _deleteAttribute

 /**
  * Delete one or more Attribute
  * @access  private
  * @param   mixed     $attribute_id     The Attribute ID or an array of IDs
  * @return  string                      The empty string on success,
  *                                      some status message on failure
  */
 function _deleteAttribute($attribute_id)
 {
     global $_ARRAYLANG;
     $arrAttributeId = $attribute_id;
     if (!is_array($attribute_id)) {
         $arrAttributeId = array($attribute_id);
     }
     foreach ($arrAttributeId as $attribute_id) {
         $objAttribute = Attribute::getById($attribute_id);
         if (!$objAttribute) {
             return \Message::error($_ARRAYLANG['TXT_SHOP_ATTRIBUTE_ERROR_NOT_FOUND']);
         }
         if (!$objAttribute->delete()) {
             return \Message::error($_ARRAYLANG['TXT_SHOP_ATTRIBUTE_ERROR_DELETING']);
         }
     }
     return \Message::ok($_ARRAYLANG['TXT_SHOP_ATTRIBUTE' . (count($arrAttributeId) > 1 ? 'S' : '') . '_SUCCESSFULLY_DELETED']);
 }
开发者ID:Niggu,项目名称:cloudrexx,代码行数:25,代码来源:ShopManager.class.php


注:本文中的Attribute::getById方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。