本文整理汇总了PHP中eZProductCollectionItem::fetch方法的典型用法代码示例。如果您正苦于以下问题:PHP eZProductCollectionItem::fetch方法的具体用法?PHP eZProductCollectionItem::fetch怎么用?PHP eZProductCollectionItem::fetch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZProductCollectionItem
的用法示例。
在下文中一共展示了eZProductCollectionItem::fetch方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCleanupList
/**
* Unit test for eZProductCollectionItem::cleanupList()
*
* Outline:
* 1) Create 40 eZProductCollectionItem objects with a product_collection_id
* from 1 to 4
* 2) Call cleanupList with (1, 2) as a parameter
* 4) Check that the 20 matching items have been removed
* 5) Check that the 20 other, non-matching items haven't been removed
**/
public function testCleanupList()
{
// Create a few collections
$row = array('product_collection_id' => 0, 'contentobject_id' => 1, 'item_count' => 1, 'price' => 50, 'is_vat_inc' => 1, 'vat_value' => 19.6, 'discount' => 0, 'name' => __FUNCTION__);
$deleteIDArray = $keepIDArray = array();
for ($i = 1; $i < 40; $i++) {
$row['productcollection_id'] = ceil($i / 10);
$row['name'] = __FUNCTION__ . ":" . $row['productcollection_id'] . "-{$i}";
$item = new eZProductCollectionItem($row);
$item->store();
if ($row['productcollection_id'] <= 2) {
$deleteIDArray[] = $item->attribute('id');
} else {
$keepIDArray[] = $item->attribute('id');
}
}
eZProductCollectionItem::cleanupList(array(1, 2));
// Check that each item of deleteIDArray has been removed
foreach ($deleteIDArray as $id) {
$this->assertNull(eZProductCollectionItem::fetch($id));
}
// And check that each item of remainingIDArray hasn't been deleted
foreach ($keepIDArray as $id) {
$this->assertType('eZProductCollectionItem', eZProductCollectionItem::fetch($id));
}
}
示例2: removeItem
function removeItem($itemID)
{
$item = eZProductCollectionItem::fetch($itemID);
if (is_object($item) && $this->attribute('productcollection_id') == $item->attribute('productcollection_id')) {
$item->remove();
}
}
示例3: addToBasket
function addToBasket($objectID, $optionList, $quantity)
{
$object = eZContentObject::fetch($objectID);
$nodeID = $object->attribute('main_node_id');
$price = 0.0;
$isVATIncluded = true;
$attributes = $object->contentObjectAttributes();
$priceFound = false;
foreach ($attributes as $attribute) {
$dataType = $attribute->dataType();
if (eZShopFunctions::isProductDatatype($dataType->isA())) {
$priceObj = $attribute->content();
$price += $priceObj->attribute('price');
$priceFound = true;
}
}
if (!$priceFound) {
eZDebug::writeError('Attempted to add object without price to basket.');
return array('status' => eZModuleOperationInfo::STATUS_CANCELLED);
}
$currency = $priceObj->attribute('currency');
// Check for 'option sets' in option list.
// If found each 'option set' will be added as a separate product purchase.
$hasOptionSet = false;
foreach (array_keys($optionList) as $optionKey) {
if (substr($optionKey, 0, 4) == 'set_') {
$returnStatus = eZShopOperationCollection::addToBasket($objectID, $optionList[$optionKey]);
// If adding one 'option set' fails we should stop immediately
if ($returnStatus['status'] == eZModuleOperationInfo::STATUS_CANCELLED) {
return $returnStatus;
}
$hasOptionSet = true;
}
}
if ($hasOptionSet) {
return $returnStatus;
}
$unvalidatedAttributes = array();
foreach ($attributes as $attribute) {
$dataType = $attribute->dataType();
if ($dataType->isAddToBasketValidationRequired()) {
$errors = array();
if ($attribute->validateAddToBasket($optionList[$attribute->attribute('id')], $errors) !== eZInputValidator::STATE_ACCEPTED) {
$description = $errors;
$contentClassAttribute = $attribute->contentClassAttribute();
$attributeName = $contentClassAttribute->attribute('name');
$unvalidatedAttributes[] = array("name" => $attributeName, "description" => $description);
}
}
}
if (count($unvalidatedAttributes) > 0) {
return array('status' => eZModuleOperationInfo::STATUS_CANCELLED, 'reason' => 'validation', 'error_data' => $unvalidatedAttributes);
}
$basket = eZBasket::currentBasket();
/* Check if the item with the same options is not already in the basket: */
$itemID = false;
$collection = $basket->attribute('productcollection');
if (!$collection) {
eZDebug::writeError('Unable to find product collection.');
return array('status' => eZModuleOperationInfo::STATUS_CANCELLED);
} else {
$collection->setAttribute('currency_code', $currency);
$collection->store();
$count = 0;
/* Calculate number of options passed via the HTTP variable: */
foreach (array_keys($optionList) as $key) {
if (is_array($optionList[$key])) {
$count += count($optionList[$key]);
} else {
$count++;
}
}
$collectionItems = $collection->itemList(false);
foreach ($collectionItems as $item) {
/* For all items in the basket which have the same object_id: */
if ($item['contentobject_id'] == $objectID) {
$options = eZProductCollectionItemOption::fetchList($item['id'], false);
/* If the number of option for this item is not the same as in the HTTP variable: */
if (count($options) != $count) {
break;
}
$theSame = true;
foreach ($options as $option) {
/* If any option differs, go away: */
if (is_array($optionList[$option['object_attribute_id']]) && !in_array($option['option_item_id'], $optionList[$option['object_attribute_id']]) || !is_array($optionList[$option['object_attribute_id']]) && $option['option_item_id'] != $optionList[$option['object_attribute_id']]) {
$theSame = false;
break;
}
}
if ($theSame) {
$itemID = $item['id'];
break;
}
}
}
if ($itemID) {
/* If found in the basket, just increment number of that items: */
$item = eZProductCollectionItem::fetch($itemID);
$item->setAttribute('item_count', $quantity + $item->attribute('item_count'));
$item->store();
//.........这里部分代码省略.........
示例4: removeItem
static function removeItem($itemID)
{
$item = eZProductCollectionItem::fetch($itemID);
$item->remove();
}
示例5:
if ($counteditems == 0) {
$zeroproduct = true;
return $module->redirectTo($module->functionURI("basket"));
}
$itemIDList = $http->postVariable("ProductItemIDList");
if (is_array($itemCountList) && is_array($itemIDList) && count($itemCountList) == count($itemIDList) && is_object($basket)) {
$productCollectionID = $basket->attribute('productcollection_id');
$db = eZDB::instance();
$db->begin();
for ($i = 0, $itemCountError = false; $i < count($itemIDList); ++$i) {
// If item count of product <= 0 we should show the error
if (!is_numeric($itemCountList[$i]) or $itemCountList[$i] <= 0) {
$itemCountError = true;
continue;
}
$item = eZProductCollectionItem::fetch($itemIDList[$i]);
if (is_object($item) && $item->attribute('productcollection_id') == $productCollectionID) {
$item->setAttribute("item_count", $itemCountList[$i]);
$item->store();
}
}
$db->commit();
if ($itemCountError) {
// Redirect to basket
$module->redirectTo($module->functionURI("basket") . "/(error)/invaliditemcount");
return;
}
}
}
// Fetch the shop account handler
$accountHandler = eZShopAccountHandler::instance();