function execute($process, $event)
 {
     $ini = eZINI::instance('workflow.ini');
     $cost = $ini->variable("SimpleShippingWorkflow", "ShippingCost");
     $description = $ini->variable("SimpleShippingWorkflow", "ShippingDescription");
     $parameters = $process->attribute('parameter_list');
     if (isset($parameters['order_id'])) {
         $orderID = $parameters['order_id'];
         $order = eZOrder::fetch($orderID);
         $orderItems = $order->attribute('order_items');
         $addShipping = true;
         foreach ($orderItems as $orderItem) {
             if ($orderItem->attribute('type') == 'ezsimpleshipping') {
                 $addShipping = false;
                 break;
             }
         }
         if ($addShipping) {
             $productCollection = $order->attribute('productcollection');
             $orderCurrency = $productCollection->attribute('currency_code');
             $cost = eZShopFunctions::convertAdditionalPrice($orderCurrency, $cost);
             $orderItem = new eZOrderItem(array('order_id' => $orderID, 'description' => $description, 'price' => $cost, 'type' => 'ezsimpleshipping'));
             $orderItem->store();
         }
     }
     return eZWorkflowType::STATUS_ACCEPTED;
 }
예제 #2
0
 function customSortingSQL($params)
 {
     $multipriceTableAlias = "mp";
     if (isset($params['table_alias_suffix'])) {
         $multipriceTableAlias .= $params['table_alias_suffix'];
     }
     $sql = array('from' => '', 'where' => '', 'sorting_field' => '');
     $sql['from'] = "ezmultipricedata {$multipriceTableAlias}";
     $and = '';
     if (isset($params['contentobject_attr_id'])) {
         $sql['where'] = "\n                     {$multipriceTableAlias}.contentobject_attr_id = {$params['contentobject_attr_id']}";
         $and = ' AND';
     }
     if (isset($params['contentobject_attr_version'])) {
         $sql['where'] .= "\n                    {$and} {$multipriceTableAlias}.contentobject_attr_version = {$params['contentobject_attr_version']}";
         $and = ' AND';
     }
     if (!isset($params['currency_code'])) {
         $params['currency_code'] = eZShopFunctions::preferredCurrencyCode();
     }
     if ($params['currency_code'] !== false) {
         $sql['where'] .= "\n                    {$and} {$multipriceTableAlias}.currency_code = '{$params['currency_code']}'";
         $and = ' AND';
     }
     $sql['sorting_field'] = "{$multipriceTableAlias}.value";
     return $sql;
 }
예제 #3
0
 function canAddProduct($contentObject)
 {
     $error = eZError::SHOP_OK;
     $productType = eZShopFunctions::productTypeByObject($contentObject);
     if ($productType === false) {
         $error = eZError::SHOP_NOT_A_PRODUCT;
     } else {
         if (!eZShopFunctions::isSimplePriceProductType($productType)) {
             $error = eZShopFunctions::isPreferredCurrencyValid();
         }
         if ($error === eZError::SHOP_OK) {
             $basketType = $this->type();
             if ($basketType !== false && $basketType !== $productType) {
                 $error = eZError::SHOP_BASKET_INCOMPATIBLE_PRODUCT_TYPE;
             }
         }
     }
     return $error;
 }
    }

    $discountRule->store();
    $db->commit();

    // we changed prices => remove content cache
    eZContentCacheManager::clearAllContentCache();

    return $module->redirectTo( $module->functionURI( 'discountgroupview' ) . '/' . $discountGroupID );
}

$classList = eZContentClass::fetchList();
$productClassList = array();
foreach ( $classList as $class )
{
    if ( eZShopFunctions::isProductClass( $class ) )
        $productClassList[] = $class;
}

$sectionList = eZSection::fetchList();

$tpl = eZTemplate::factory();

$tpl->setVariable( 'module', $module );
$tpl->setVariable( 'discountgroup_id', $discountGroupID );
$tpl->setVariable( 'discountrule', $discountRule );

$tpl->setVariable( 'product_class_list', $productClassList );
$tpl->setVariable( 'section_list', $sectionList );

$tpl->setVariable( 'class_limitation_list', $discountRuleSelectedClasses );
예제 #5
0
 static function isPreferredCurrencyValid($currencyCode = false)
 {
     $error = eZError::SHOP_OK;
     if ($currencyCode === false) {
         $currencyCode = eZShopFunctions::preferredCurrencyCode();
     }
     $currency = eZCurrencyData::fetch($currencyCode);
     if ($currency) {
         if (!$currency->isActive()) {
             $error = eZError::SHOP_PREFERRED_CURRENCY_INACTIVE;
             eZDebug::writeWarning("Currency '{$currencyCode}' is inactive.", __METHOD__);
         }
     } else {
         $error = eZError::SHOP_PREFERRED_CURRENCY_DOESNOT_EXIST;
         eZDebug::writeWarning("Currency '{$currencyCode}' doesn't exist", __METHOD__);
     }
     return $error;
 }
    function fetchUserCountry()
    {
        // Get country saved in user preferences.
        $country = eZShopFunctions::getPreferredUserCountry();
        if ( !$country )
        {
            // If not found, get country from user object
            // and save it to the preference.
            $country = eZShopFunctions::getUserCountry();
            if ( $country )
                eZShopFunctions::setPreferredUserCountry( $country );
        }

        return array( 'result' => $country );
    }
<?php
/**
 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved.
 * @license http://ez.no/Resources/Software/Licenses/eZ-Business-Use-License-Agreement-eZ-BUL-Version-2.1 eZ Business Use License Agreement eZ BUL Version 2.1
 * @version 4.7.0
 * @package kernel
 */

$module = $Params['Module'];

$preferredCurrency = $Params['Currency'];

if ( $module->isCurrentAction( 'Set' ) )
{
    if ( $module->hasActionParameter( 'Currency' ) )
        $preferredCurrency = $module->actionParameter( 'Currency' );
}

if ( $preferredCurrency )
    eZShopFunctions::setPreferredCurrencyCode( $preferredCurrency );

eZRedirectManager::redirectTo( $module, false );

?>
예제 #8
0
                        if ($updateData['rate_factor'] == '') {
                            $currency->setAttribute('rate_factor', 0);
                        }
                    }
                    $currency->sync();
                }
            }
            $db->commit();
            $error = array('code' => 0, 'description' => ezpI18n::tr('kernel/shop', 'Changes were stored successfully.'));
        } else {
            if ($module->isCurrentAction('UpdateAutoprices')) {
                $error = eZShopFunctions::updateAutoprices();
                eZContentCacheManager::clearAllContentCache();
            } else {
                if ($module->isCurrentAction('UpdateAutoRates')) {
                    $error = eZShopFunctions::updateAutoRates();
                }
            }
        }
    }
}
if ($error !== false) {
    if ($error['code'] != 0) {
        $error['style'] = 'message-error';
    } else {
        $error['style'] = 'message-feedback';
    }
}
switch (eZPreferences::value('currencies_list_limit')) {
    case '2':
        $limit = 25;
예제 #9
0
 function preferredCurrencyCode()
 {
     return eZShopFunctions::preferredCurrencyCode();
 }
 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();
         } else {
             $item = eZProductCollectionItem::create($basket->attribute("productcollection_id"));
             $item->setAttribute('name', $object->attribute('name'));
             $item->setAttribute("contentobject_id", $objectID);
             $item->setAttribute("item_count", $quantity);
             $item->setAttribute("price", $price);
             if ($priceObj->attribute('is_vat_included')) {
                 $item->setAttribute("is_vat_inc", '1');
             } else {
                 $item->setAttribute("is_vat_inc", '0');
             }
             $item->setAttribute("vat_value", $priceObj->attribute('vat_percent'));
             $item->setAttribute("discount", $priceObj->attribute('discount_percent'));
             $item->store();
             $priceWithoutOptions = $price;
             $optionIDList = array();
             foreach (array_keys($optionList) as $key) {
                 $attributeID = $key;
                 $optionString = $optionList[$key];
                 if (is_array($optionString)) {
                     foreach ($optionString as $optionID) {
                         $optionIDList[] = array('attribute_id' => $attributeID, 'option_string' => $optionID);
                     }
                 } else {
                     $optionIDList[] = array('attribute_id' => $attributeID, 'option_string' => $optionString);
                 }
             }
             $db = eZDB::instance();
             $db->begin();
             foreach ($optionIDList as $optionIDItem) {
                 $attributeID = $optionIDItem['attribute_id'];
                 $optionString = $optionIDItem['option_string'];
                 $attribute = eZContentObjectAttribute::fetch($attributeID, $object->attribute('current_version'));
                 $dataType = $attribute->dataType();
                 $optionData = $dataType->productOptionInformation($attribute, $optionString, $item);
                 if ($optionData) {
                     $optionData['additional_price'] = eZShopFunctions::convertAdditionalPrice($currency, $optionData['additional_price']);
                     $optionItem = eZProductCollectionItemOption::create($item->attribute('id'), $optionData['id'], $optionData['name'], $optionData['value'], $optionData['additional_price'], $attributeID);
                     $optionItem->store();
                     $price += $optionData['additional_price'];
                 }
             }
             if ($price != $priceWithoutOptions) {
                 $item->setAttribute("price", $price);
                 $item->store();
             }
             $db->commit();
         }
     }
     return array('status' => eZModuleOperationInfo::STATUS_CONTINUE);
 }
예제 #11
0
    /**
     * Determine user's country.
     *
     * \public
     * \static
     */
    static function getUserCountry( $user = false, $considerPreferedCountry = true )
    {
        $requireUserCountry = eZVATManager::isUserCountryRequired();

        // If current user has set his/her preferred country via the toolbar
        if ( $considerPreferedCountry )
        {
            // return it
            $country = eZShopFunctions::getPreferredUserCountry();
            if ( $country )
            {
                eZDebug::writeDebug( "Applying user's preferred country <$country> while charging VAT" );
                return $country;
            }
        }

        // Otherwise fetch country saved in the user object.

        if ( $user === false )
        {
            $user = eZUser::currentUser();
        }

        $userObject = $user->attribute( 'contentobject' );
        $countryAttributeName = eZVATManager::getUserCountryAttributeName( $requireUserCountry );

        if ( $countryAttributeName === null )
            return null;

        $userDataMap = $userObject->attribute( 'data_map' );
        if ( !isset( $userDataMap[$countryAttributeName] ) )
        {
            if ( $requireUserCountry )
            {
                eZDebug::writeError( "Cannot find user country: there is no attribute '$countryAttributeName' in object '" .
                                       $userObject->attribute( 'name' ) .
                                       "' of class '" .
                                       $userObject->attribute( 'class_name' ) . "'.",
                                     __METHOD__ );
            }
            return null;
        }

        $countryAttribute = $userDataMap[$countryAttributeName];
        $countryContent = $countryAttribute->attribute( 'content' );

        if ( $countryContent === null )
        {
            if ( $requireUserCountry )
            {
                eZDebug::writeError( "User country is not specified in object '" .
                                       $userObject->attribute( 'name' ) .
                                       "' of class '" .
                                       $userObject->attribute( 'class_name' ) . "'." ,
                                     __METHOD__ );
            }
            return null;
        }

        if ( is_object( $countryContent ) )
            $country = $countryContent->attribute( 'value' );
        elseif ( is_array( $countryContent ) )
        {
            if ( is_array( $countryContent['value'] ) )
            {
                foreach ( $countryContent['value'] as $item )
                {
                    $country = $item['Alpha2'];
                    break;
                }
            }
            else
            {
                $country = $countryContent['value'];
            }
        }
        else
        {
            if ( $requireUserCountry )
            {
                eZDebug::writeError( "User country is not specified or specified incorrectly in object '" .
                                       $userObject->attribute( 'name' ) .
                                       "' of class '" .
                                       $userObject->attribute( 'class_name' ) . "'." ,
                                     __METHOD__ );
            }
            return null;
        }

        return $country;
    }
            if ( $productClassItem->attribute( 'identifier' ) === $productClassIdentifier )
            {
                $productClass = $productClassItem;
                break;
            }
        }
    }
    else
    {
        // use first element of $productClassList
        $productClass = $productClassList[0];
    }
}

if ( is_object( $productClass ) )
    $priceAttributeIdentifier = eZShopFunctions::priceAttributeIdentifier( $productClass );

switch ( eZPreferences::value( 'productsoverview_list_limit' ) )
{
    case '2': { $limit = 25; } break;
    case '3': { $limit = 50; } break;
    default:  { $limit = 10; } break;
}

$sortingField = eZPreferences::value( 'productsoverview_sorting_field' );
$sortingOrder = eZPreferences::value( 'productsoverview_sorting_order' );

$viewParameters = array( 'offset' => $offset );

$tpl = eZTemplate::factory();
$tpl->setVariable( 'product_class_list', $productClassList );
예제 #13
0
        $root->appendChild($placeNode);
        $stateNode = $doc->createElement("state", $state);
        $root->appendChild($stateNode);
        $countryNode = $doc->createElement("country", $country);
        $root->appendChild($countryNode);
        $commentNode = $doc->createElement("comment", $comment);
        $root->appendChild($commentNode);
        $collectNode = $doc->createElement("collect", $collect);
        $root->appendChild($collectNode);
        $xmlString = $doc->saveXML();
        $order->setAttribute('data_text_1', $xmlString);
        $order->setAttribute('account_identifier', "twrv2");
        $order->setAttribute('ignore_vat', 0);
        $order->store();
        $db->commit();
        eZShopFunctions::setPreferredUserCountry($country);
        $http->setSessionVariable('MyTemporaryOrderID', $order->attribute('id'));
        $module->redirectTo('/shop/confirmorder/');
        return;
    } else {
        $tpl->setVariable("input_error", true);
    }
}
$tpl->setVariable("first_name", $firstName);
$tpl->setVariable("last_name", $lastName);
$tpl->setVariable("email", $email);
$tpl->setVariable("street1", $street1);
$tpl->setVariable("street2", $street2);
$tpl->setVariable("zip", $zip);
$tpl->setVariable("place", $place);
$tpl->setVariable("state", $state);
예제 #14
0
         $error = eZCurrencyData::errorMessage($errCode);
     } else {
         $error = validateCurrencyData($currencyParams);
         if ($error === false) {
             eZShopFunctions::createCurrency($currencyParams);
             eZContentCacheManager::clearAllContentCache();
             return $module->redirectTo($module->functionURI('currencylist'));
         }
     }
 } else {
     if ($module->isCurrentAction('StoreChanges')) {
         $originalCurrencyCode = $module->hasActionParameter('OriginalCurrencyCode') ? $module->actionParameter('OriginalCurrencyCode') : '';
         if ($module->hasActionParameter('CurrencyData')) {
             $currencyParams = $module->actionParameter('CurrencyData');
         }
         $errCode = eZShopFunctions::changeCurrency($originalCurrencyCode, $currencyParams['code']);
         if ($errCode === eZCurrencyData::ERROR_OK) {
             $error = validateCurrencyData($currencyParams);
             if ($error === false) {
                 $currency = eZCurrencyData::fetch($currencyParams['code']);
                 if (is_object($currency)) {
                     $currency->setAttribute('symbol', $currencyParams['symbol']);
                     $currency->setAttribute('locale', $currencyParams['locale']);
                     $currency->setAttribute('custom_rate_value', $currencyParams['custom_rate_value']);
                     $currency->setAttribute('rate_factor', $currencyParams['rate_factor']);
                     $db = eZDB::instance();
                     $db->begin();
                     $currency->sync();
                     $db->commit();
                     eZContentCacheManager::clearAllContentCache();
                     return $module->redirectTo($module->functionURI('currencylist'));
예제 #15
0
$db->begin();
foreach ($classList as $class) {
    if (eZShopFunctions::isSimplePriceClass($class)) {
        $classID = $class->attribute('id');
        $objectListCount = eZContentObject::fetchSameClassListCount($classID);
        if ($objectListCount == 0) {
            $cli->output("No objects found for '" . $class->attribute('name') . "' class");
            continue;
        }
        $cli->output("Processing objects of the '" . $class->attribute('name') . "' class");
        $defaultCurrency = currencyForLocale();
        if (!$defaultCurrency) {
            $script->shutdown(1);
        }
        $defaultCurrencyCode = $defaultCurrency->attribute('code');
        $priceClassAttribute = eZShopFunctions::priceAttribute($class);
        $priceClassAttributeID = $priceClassAttribute->attribute('id');
        // replace 'ezprice' class attribute with 'ezmultiprice'.
        $priceClassAttribute->setAttribute('data_type_string', 'ezmultiprice');
        $priceClassAttribute->setAttribute(eZMultiPriceType::DEFAULT_CURRENCY_CODE_FIELD, $defaultCurrencyCode);
        $priceClassAttribute->store();
        unset($GLOBALS['eZContentClassAttributeCache'][$priceClassAttributeID]);
        // update objects
        $offset = 0;
        $limit = 1000;
        $cli->output('Converting', false);
        while ($offset < $objectListCount) {
            $objectList = eZContentObject::fetchSameClassList($class->attribute('id'), true, $offset, $limit);
            $offset += count($objectList);
            foreach ($objectList as $object) {
                $contentObjectID = $object->attribute('id');
 function verify($currency = false)
 {
     $contentObject = $this->attribute('contentobject');
     if ($contentObject != null && $contentObject->attribute('main_node_id') > 0) {
         $attributes = $contentObject->contentObjectAttributes();
         $optionsPrice = $this->calculatePriceWithOptions($currency);
         foreach ($attributes as $attribute) {
             $dataType = $attribute->dataType();
             if (eZShopFunctions::isProductDatatype($dataType->isA())) {
                 $priceObj = $attribute->content();
                 $price = $priceObj->attribute('price');
                 $priceWithOptions = $price + $optionsPrice;
                 if ($priceWithOptions != $this->attribute('price')) {
                     return false;
                 }
                 if ($priceObj->attribute('is_vat_included') != $this->attribute('is_vat_inc') > 0) {
                     return false;
                 }
                 if ($priceObj->attribute('vat_percent') != $this->attribute('vat_value')) {
                     return false;
                 }
                 if ($priceObj->discount() != $this->attribute('discount')) {
                     return false;
                 }
                 return true;
             }
         }
     }
     return false;
 }