/**
  * Unit test for eZDiscountRule::fetchByUserIDArray()
  */
 public function testFetchByUserIDArray()
 {
     // Create 5 few discount rules
     $discountRules = array();
     for ($i = 0; $i < 5; $i++) {
         $row = array('name' => __FUNCTION__ . " #{$i}");
         $rule = new eZDiscountRule($row);
         $rule->store();
         $discountRules[] = $rule;
     }
     // Create 5 user discount rules for 3 different user IDs
     $usersDiscountRules = array();
     foreach (array(1, 3) as $userID) {
         $usersDiscountRules[$userID] = array();
         $userDiscountRules =& $usersDiscountRules[$userID];
         foreach ($discountRules as $discountRule) {
             $row = array('discountrule_id' => $discountRule->attribute('id'), 'contentobject_id' => $userID);
             $userDiscountRule = new eZUserDiscountRule($row);
             $userDiscountRule->store();
             $userDiscountRules[] = $userDiscountRule;
         }
     }
     // fetch the discount rules for user #1 and #2. This will match 10
     // eZUserDiscountRule, and return the 5 rules, since no duplicates will
     // be returned
     $rules = eZUserDiscountRule::fetchByUserIDArray(array(1, 2));
     $this->assertInternalType('array', $rules, "Return value should have been an array");
     $this->assertEquals(5, count($rules), "Return value should contain 5 items");
     foreach ($rules as $rule) {
         $this->assertInstanceOf('eZDiscountRule', $rule);
     }
 }
<?php

/**
 * @copyright Copyright (C) 1999-2013 eZ Systems AS. All rights reserved.
 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
 * @version  2013.11
 * @package kernel
 */
$module = $Params['Module'];
$discountGroupID = null;
if (isset($Params["DiscountGroupID"])) {
    $discountGroupID = $Params["DiscountGroupID"];
}
$discountGroup = eZDiscountRule::fetch($discountGroupID);
if ($discountGroup === null) {
    return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
}
$http = eZHTTPTool::instance();
if ($http->hasPostVariable("AddRuleButton")) {
    return $module->redirectTo($module->functionURI('discountruleedit') . '/' . $discountGroupID);
}
if ($http->hasPostVariable("RemoveRuleButton")) {
    $discountRuleIDList = $http->postVariable("removeRuleList");
    $db = eZDB::instance();
    $db->begin();
    foreach ($discountRuleIDList as $discountRuleID) {
        eZDiscountSubRuleValue::removeBySubRuleID($discountRuleID);
        eZDiscountSubRule::remove($discountRuleID);
    }
    $db->commit();
    // we changed prices => remove content cache
 static function removeByID($id)
 {
     eZPersistentObject::removeObject(eZDiscountRule::definition(), array("id" => $id));
 }
 * @version //autogentag//
 * @package kernel
 */

$module = $Params['Module'];
$discountGroupID = null;
if ( isset( $Params["DiscountGroupID"] ) )
    $discountGroupID = $Params["DiscountGroupID"];

if ( is_numeric( $discountGroupID ) )
{
    $discountGroup = eZDiscountRule::fetch( $discountGroupID );
}
else
{
    $discountGroup = eZDiscountRule::create();
    $discountGroupID = $discountGroup->attribute( "id" );
}

$http = eZHTTPTool::instance();
if ( $http->hasPostVariable( "DiscardButton" ) )
{
    $module->redirectTo( $module->functionURI( "discountgroup" ) . "/" );
    return;
}
if ( $http->hasPostVariable( "ApplyButton" ) )
{
    if ( $http->hasPostVariable( "discount_group_name" ) )
    {
        $name = $http->postVariable( "discount_group_name" );
    }
Exemple #5
0
$http = eZHTTPTool::instance();
$discountGroupArray = eZDiscountRule::fetchList();
if ($http->hasPostVariable("AddDiscountGroupButton")) {
    $params = array();
    $Module->redirectTo($Module->functionURI("discountgroupedit"));
    return;
}
if ($http->hasPostVariable("EditGroupButton") && $http->hasPostVariable("EditGroupID")) {
    $Module->redirectTo($Module->functionURI("discountgroupedit") . "/" . $http->postVariable("EditGroupID"));
    return;
}
if ($http->hasPostVariable("RemoveDiscountGroupButton")) {
    $discountRuleIDList = $http->postVariable("discountGroupIDList");
    $db = eZDB::instance();
    $db->begin();
    foreach ($discountRuleIDList as $discountRuleID) {
        eZDiscountRule::removeByID($discountRuleID);
    }
    $db->commit();
    // we changed prices of products (no discount now) => remove content caches
    eZContentCacheManager::clearAllContentCache();
    $module->redirectTo($module->functionURI("discountgroup") . "/");
    return;
}
$module->setTitle("View discount group");
$tpl = eZTemplate::factory();
$tpl->setVariable("discountgroup_array", $discountGroupArray);
$tpl->setVariable("module", $module);
$Result = array();
$Result['content'] = $tpl->fetch("design:shop/discountgroup.tpl");
$Result['path'] = array(array('url' => '/shop/discountgroup/', 'text' => ezpI18n::tr('kernel/shop', 'Discount group')));