Beispiel #1
0
 /**
  * Test get tax rate for class id.
  */
 public function testGetRateForClassId()
 {
     $taxService = $this->get('taxService');
     $taxRate = $taxService->getTaxRateForClassId(1, 223, 18);
     $this->assertNotNull($taxRate);
     $this->assertTrue($taxRate instanceof \ZenMagick\StoreBundle\Entity\TaxRate);
     if ($taxRate) {
         $this->assertEquals('1_223_18', $taxRate->getId());
         $this->assertEquals(1, $taxRate->getClassId());
         $this->assertEquals(223, $taxRate->getCountryId());
         $this->assertEquals(18, $taxRate->getZoneId());
         // check for 7 decimal digits
         $this->assertEquals(7.0, $taxRate->getRate());
     }
     // test non existing
     $taxRate = $taxService->getTaxRateForClassId(2, 223, 18);
     $this->assertNotNull($taxRate);
     $this->assertTrue($taxRate instanceof \ZenMagick\StoreBundle\Entity\TaxRate);
     if ($taxRate) {
         $this->assertEquals(2, $taxRate->getClassId());
         $this->assertEquals(Runtime::getSettings()->get('storeCountry'), $taxRate->getCountryId());
         $this->assertEquals(Runtime::getSettings()->get('storeZone'), $taxRate->getZoneId());
         // check for 6 decimal digits
         $this->assertEquals(0, $taxRate->getRate());
     } else {
         $this->fail('no default tax rate not found');
     }
 }
Beispiel #2
0
 /**
  * Encode a given string to valid HTML.
  *
  * @param string s The string to encode.
  * @return string The encoded HTML.
  */
 public static function encode($s)
 {
     $charset = Runtime::getSettings()->get('zenmagick.http.html.charset');
     $s = html_entity_decode($s, ENT_QUOTES, $charset);
     $s = htmlentities($s, ENT_QUOTES, $charset);
     return $s;
 }
 /**
  * Validate the given request data.
  *
  * @param ZenMagick\Http\Request request The current request.
  * @param array data The data.
  * @return boolean <code>true</code> if the value for <code>$name</code> is valid, <code>false</code> if not.
  */
 public function validate($request, $data)
 {
     if (!Runtime::getSettings()->get('isAccountState')) {
         return true;
     }
     //todo: this should not be here, but in the corresponding controller classes - BEFORE the validation is done
     $state = isset($data['state']) ? $data['state'] : null;
     $zoneId = isset($data['zoneId']) ? $data['zoneId'] : null;
     $zones = $this->container->get('countryService')->getZonesForCountryId($data['countryId']);
     $valid = false;
     if (0 < count($zones)) {
         // need $state to match either an id or name
         foreach ($zones as $zone) {
             if ($zone->getName() == $state || $zone->getId() == $state || $zone->getId() == $zoneId || $zone->getCode() == $state) {
                 $zoneId = $zone->getId();
                 $state = '';
                 $valid = true;
                 break;
             }
         }
     } else {
         if (!empty($state)) {
             $valid = true;
             $zoneId = 0;
         }
     }
     // check for form bean
     if (array_key_exists('__obj', $data)) {
         $data['__obj'] = Beans::setAll($data['__obj'], array('state' => $state, 'zoneId' => $zoneId));
     }
     return $valid;
 }
Beispiel #4
0
 /**
  * Create new result list.
  */
 public function __construct()
 {
     parent::__construct();
     $this->resultSource = null;
     $this->filters = array();
     $this->sorters = array();
     $this->page = 1;
     $this->pagination = Runtime::getSettings()->get('zenmagick.mvc.resultlist.defaultPagination');
     $this->allResults = null;
     $this->results = null;
 }
 /**
  * {@inheritDoc}
  */
 public function getOptions($request)
 {
     $options = parent::getOptions($request);
     // try to find a useful countryId, defaulting to store country Id
     $countryId = Runtime::getSettings()->get('storeCountry');
     //XXX: where else to look ??
     foreach ($this->container->get('countryService')->getZonesForCountryId($countryId) as $zone) {
         $options[$zone->getId()] = $zone->getName();
     }
     return $options;
 }
Beispiel #6
0
 /**
  * Validate the given request data.
  *
  * @param ZenMagick\Http\Request request The current request.
  * @param array data The data.
  * @return boolean <code>true</code> if the value for <code>$name</code> is valid, <code>false</code> if not.
  */
 public function validate($request, $data)
 {
     if (empty($data[$this->getName()])) {
         return true;
     }
     $amount = $data[$this->getName()];
     $account = $this->container->get('security.context')->getToken()->getUser();
     $balance = $account->getVoucherBalance();
     $currentCurrencyCode = $request->getSession()->get('currency');
     if (Runtime::getSettings()->get('defaultCurrency') != $currentCurrencyCode) {
         // need to convert amount to default currency as GV values are in default currency
         $currency = $this->container->get('currencyService')->getCurrencyForCode($currentCurrencyCode);
         $amount = $currency->convertFrom($amount);
     }
     if (0 == $amount || $amount > $balance) {
         return false;
     }
     return true;
 }
Beispiel #7
0
 /**
  * Load attributes for the given product.
  *
  * @param ZenMagick\StoreBundle\Entity\Product product The product.
  * @return boolean <code>true</code> if attributes eixst, <code>false</code> if not.
  */
 public function getAttributesForProduct($product)
 {
     // set up sort order SQL
     $attributesOrderBy = '';
     if (Runtime::getSettings()->get('isSortAttributesByName')) {
         $attributesOrderBy = ' ORDER BY po.products_options_name';
     } else {
         $attributesOrderBy = ' ORDER BY LPAD(po.products_options_sort_order, 11, "0")';
     }
     $sql = "SELECT distinct po.products_options_id, po.products_options_name, po.products_options_sort_order,\n                po.products_options_type, po.products_options_length, po.products_options_comment, po.products_options_size,\n                po.products_options_images_per_row, po.products_options_images_style, pa.products_id\n                FROM %table.products_options% po, %table.products_attributes% pa\n                WHERE pa.products_id = :productId\n                  AND pa.options_id = po.products_options_id\n                  AND po.language_id = :languageId" . $attributesOrderBy;
     $args = array('productId' => $product->getId(), 'languageId' => $product->getLanguageId());
     $attributes = \ZMRuntime::getDatabase()->fetchAll($sql, $args, array('products_options', 'products_attributes'), 'ZenMagick\\StoreBundle\\Entity\\Catalog\\Attribute');
     if (0 == count($attributes)) {
         return $attributes;
     }
     // put in map for easy lookup
     $attributeMap = array();
     foreach ($attributes as $attribute) {
         $attributeMap[$attribute->getId()] = $attribute;
     }
     $sql = "SELECT pov.products_options_values_id, pov.products_options_values_name, pa.*\n                FROM %table.products_attributes% pa, %table.products_options_values% pov\n                WHERE pa.products_id = :productId\n                  AND pa.options_id IN (:attributeId)\n                  AND pa.options_values_id = pov.products_options_values_id\n                  AND pov.language_id = :languageId ";
     // set up sort order SQL
     if (Runtime::getSettings()->get('isSortAttributeValuesByPrice')) {
         $sql .= ' ORDER BY pa.options_id, LPAD(pa.products_options_sort_order, 11, "0"), pa.options_values_price';
     } else {
         $sql .= ' ORDER BY pa.options_id, LPAD(pa.products_options_sort_order, 11, "0"), pov.products_options_values_name';
     }
     // read all in one go
     $args = array('attributeId' => array_keys($attributeMap), 'productId' => $product->getId(), 'languageId' => $product->getLanguageId());
     $mapping = array('products_options_values', 'products_attributes');
     foreach (\ZMRuntime::getDatabase()->fetchAll($sql, $args, $mapping, 'ZMAttributeValue') as $value) {
         $attribute = $attributeMap[$value->getAttributeId()];
         $value->setAttribute($attribute);
         $value->setTaxRate($product->getTaxRate());
         $attribute->addValue($value);
     }
     return $attributes;
 }
 /**
  * {@inheritDoc}
  */
 public function populate($raw)
 {
     $recommendations = new ZMLiftSuggestRecommendations();
     $recommended = $this->getFromSession('reco_prods', array());
     // process product infos
     $products = array();
     foreach ($raw['products'] as $details) {
         if (array_key_exists('sku', $details)) {
             $product = $this->container->get('productService')->getProductForId($details['sku'], Runtime::getSettings()->get('storeDefaultLanguageId'));
             if (null != $product && $product->getStatus()) {
                 $info = array('product' => null, 'info' => array());
                 foreach ($details as $key => $value) {
                     if ('sku' == $key) {
                         $info['product'] = $product;
                         $recommended[] = $product->getId();
                     } else {
                         // other details
                         $info['info'][$key] = $value;
                     }
                 }
                 $products[] = $info;
             }
         }
     }
     $recommendations->set('productDetails', $products);
     // keep other
     foreach ($raw as $key => $details) {
         if ('products' != $key) {
             $recommendations->set($key, $details);
             if ('popular_perc' == $key) {
                 $recommendations->set('popularity', $details);
             }
         }
     }
     $this->storeInSession('reco_prods', $recommended);
     return $recommendations;
 }
Beispiel #9
0
 /**
  * Apply user/group settings to file(s) that should allow ftp users to modify/delete them.
  *
  * <p>The file group attribute is only going to be changed if the <code>$perms</code> parameter is not empty.</p>
  *
  * <p>This method may be disabled by setting <em>zenmagick.core.fs.permissions.fix</em> to <code>false</code>.</p>
  *
  * @param mixed files Either a single filename or list of files.
  * @param boolean recursive Optional flag to recursively process all files/folders in a given directory; default is <code>false</code>.
  * @param array perms Optional file permissions; defaults are taken from the settings <em>fs.permissions.defaults.folder</em> for folder,
  *  <em>fs.permissions.defaults.file</em> for files.
  *
  * @todo rewrite to use Symfony\Component\Filesystem methods.
  */
 public function setFilePerms($files, $recursive = false, $perms = array())
 {
     $settingsService = Runtime::getSettings();
     if (!$settingsService->get('zenmagick.core.fs.permissions.fix')) {
         return;
     }
     if (null == $this->fileOwner || null == $this->fileGroup) {
         clearstatcache();
         $this->fileOwner = fileowner(__FILE__);
         $this->fileGroup = filegroup(__FILE__);
         if (0 == $this->fileOwner && 0 == $this->fileGroup) {
             return;
         }
     }
     if (!is_array($files)) {
         $files = array($files);
     }
     $filePerms = array_merge(array('file' => $settingsService->get('zenmagick.core.fs.permissions.defaults.file', '0644'), 'folder' => $settingsService->get('zenmagick.core.fs.permissions.defaults.folder', '0755')), $perms);
     foreach ($filePerms as $type => $perms) {
         if (is_string($perms)) {
             $filePerms[$type] = intval($perms, 8);
         }
     }
     foreach ($files as $file) {
         if (0 < count($perms)) {
             @chgrp($file, $this->fileGroup);
         }
         @chown($file, $this->fileOwner);
         $mod = $filePerms[is_dir($file) ? 'folder' : 'file'];
         @chmod($file, $mod);
         if (is_dir($file) && $recursive) {
             $dir = $file;
             $dir = rtrim($dir, '/') . '/';
             $subfiles = array();
             $handle = @opendir($dir);
             while (false !== ($file = readdir($handle))) {
                 if ("." == $file || ".." == $file) {
                     continue;
                 }
                 $subfiles[] = $dir . $file;
             }
             @closedir($handle);
             $this->setFilePerms($subfiles, $recursive, $perms);
         }
     }
 }
 /**
  * Email.
  *
  * @param ZenMagick\StoreBundle\Entity\Order\Order order The order.
  */
 protected function sendOrderEmail($order, $template)
 {
     $shippingAddress = $order->getShippingAddress();
     $billingAddress = $order->getBillingAddress();
     $paymentType = $order->getPaymentType();
     $translator = $this->container->get('translator');
     $settingsService = $this->container->get('settingsService');
     $context = array();
     $context['order'] = $order;
     $context['shippingAddress'] = $shippingAddress;
     $context['billingAddress'] = $billingAddress;
     $context['paymentType'] = $paymentType;
     // for comaptibility when using the checkout template
     $context['INTRO_ORDER_NUMBER'] = $order->getId();
     $account = $order->getAccount();
     $subject = $translator->trans('%store_name%: Order Subscription Notification', array('%store_name%' => $settingsService->get('storeName')));
     $message = $this->container->get('messageBuilder')->createMessage($template, true, $request, $context);
     $message->setSubject($subject)->setTo($account->getEmail())->setFrom(Runtime::getSettings()->get('storeEmail'));
     $this->container->get('mailer')->send($message);
 }
 /**
  * Get a zen-cart style address (array) .
  *
  * @return array Array containing a zen-cart style address.
  */
 public function getZCAddress()
 {
     global $order, $country_info;
     $address = null;
     $countryService = Runtime::getContainer()->get('countryService');
     $request = $this->getRequest();
     $countryId = $request->request->get('country_id');
     if (null != $countryId) {
         // country is selected
         $country_info = $_SESSION['country_info'];
         $address = array('postcode' => $this->getPostcode(), 'country' => array('id' => $countryId, 'title' => $country_info['countries_name'], 'iso_code_2' => $country_info['countries_iso_code_2'], 'iso_code_3' => $country_info['countries_iso_code_3']), 'country_id' => $countryId, 'zone_id' => $this->getStateId(), 'format_id' => $countryService->getCountryForId($countryId)->getAddressFormatId());
         $_SESSION['cart_country_id'] = $countryId;
         //add state zone_id
         $_SESSION['cart_zone'] = $this->getStateId();
         $_SESSION['cart_zip_code'] = $this->getPostcode();
     } elseif ($_SESSION['cart_country_id']) {
         // session is available
         $country_info = $_SESSION['country_info'];
         // fix here - check for error on $cart_country_id
         $address = array('postcode' => $_SESSION['cart_zip_code'], 'country' => array('id' => $_SESSION['cart_country_id'], 'title' => $country_info['countries_name'], 'iso_code_2' => $country_info['countries_iso_code_2'], 'iso_code_3' => $country_info['countries_iso_code_3']), 'country_id' => $_SESSION['cart_country_id'], 'format_id' => $countryService->getCountryForId($_SESSION['cart_country_id'])->getAddressFormatId());
     } else {
         // first timer
         $_SESSION['cart_country_id'] = Runtime::getSettings()->get('storeCountry');
         $country_info = $_SESSION['country_info'];
         $address = array('country' => array('id' => Runtime::getSettings()->get('storeCountry'), 'title' => $country_info['countries_name'], 'iso_code_2' => $country_info['countries_iso_code_2'], 'iso_code_3' => $country_info['countries_iso_code_3']), 'country_id' => Runtime::getSettings()->get('storeCountry'), 'format_id' => $countryService->getCountryForId($_SESSION['cart_country_id'])->getAddressFormatId());
     }
     return $address;
 }
Beispiel #12
0
 protected function formatCrumbtrail()
 {
     if (null == $this->crumbtrail) {
         return null;
     }
     $crumbs = $this->crumbtrail->getCrumbs();
     array_shift($crumbs);
     $first = true;
     $value = '';
     foreach ($crumbs as $crumb) {
         if (!$first) {
             $value .= Runtime::getSettings()->get('metaTagCrumbtrailDelimiter');
         }
         $first = false;
         $value .= $crumb->getName();
     }
     return $value;
 }
 /**
  * Create new instance.
  */
 public function __construct()
 {
     parent::__construct();
     $this->request = null;
     $this->languageId = Runtime::getSettings()->get('storeDefaultLanguageId');
 }
Beispiel #14
0
 /**
  * Get random products marked as specials.
  *
  * @param int max The maximum number of results; default is <code>null</code> to use the setting <em>maxSpecialProducts</em>.
  * @param int languageId Optional language id; default is <code>null</code> for session language.
  * @return array A list of <code>ZenMagick\StoreBundle\Entity\Product</code> instances.
  */
 public function getSpecials($max = null, $languageId = null)
 {
     $max = null === $max ? Runtime::getSettings()->get('maxSpecialProducts') : $max;
     $sql = "select distinct p.products_id\n                from %table.products% p, %table.specials% s\n                where p.products_status = 1\n                  AND p.products_id = s.products_id\n                  AND s.status = 1";
     $productIds = 0 !== $max ? $this->getRandomProductIds($sql, $max) : $this->getProductIds($sql);
     return $this->getProductsForIds($productIds, false, $languageId);
 }
Beispiel #15
0
 /**
  * Get downloads for order.
  *
  * @param int orderId The order id.
  * @param array orderStatusList Optional array of order stati to check; default is null to use the configured range, (empty array will load all).
  * @return array A list of <code>ZenMagick\StoreBundle\Entity\Order\Download</code> instances.
  */
 public function getDownloadsForOrderId($orderId, $orderStatusList = null)
 {
     if (null === $orderStatusList) {
         // build default list
         $orderStatusList = $this->parseRange(Runtime::getSettings()->get('downloadOrderStatusRange'));
     }
     $sql = "SELECT o.date_purchased, o.orders_status, opd.*\n                FROM %table.orders% o, %table.orders_products% op, %table.orders_products_download% opd\n                WHERE o.orders_id = :orderId\n                  AND o.orders_id = op.orders_id\n                  AND op.orders_products_id = opd.orders_products_id\n                  AND opd.orders_products_filename != ''";
     if (0 < count($orderStatusList)) {
         $sql .= ' AND o.orders_status in (:orderStatusId)';
     }
     $mapping = array('orders_products_download', 'orders_products', 'orders');
     return \ZMRuntime::getDatabase()->fetchAll($sql, array('orderId' => $orderId, 'orderStatusId' => $orderStatusList), $mapping, 'ZenMagick\\StoreBundle\\Entity\\Order\\Download');
 }
 /**
  * Get the price factor charge.
  *
  * <p>The setting <em>'isDiscountAttributePriceFactor'</em> will determine whether to use
  * the discount or regular price.</p>
  *
  * @param float price The calculated price.
  * @param float discountPrice The discounted price (if any).
  * @param float priceFactor The price factor.
  * @param int priceFactorOffset The price factopr offset.
  * @return float The price factor price.
  */
 protected function getPriceFactorCharge($price, $discountPrice, $priceFactor, $priceFactorOffset)
 {
     if (Runtime::getSettings()->get('isDiscountAttributePriceFactor') && 0 != $discountPrice) {
         return $discountPrice * ($priceFactor - $priceFactorOffset);
     } else {
         return $price * ($priceFactor - $priceFactorOffset);
     }
 }
Beispiel #17
0
 /**
  * Calculate the (best) price.
  */
 protected function calculatePrice()
 {
     if (null != $this->product) {
         $basePrice = $this->getBasePrice(false);
         $specialPrice = $this->getSpecialPrice(false);
         $salePrice = $this->getSalePrice(false);
         // calculate discount
         $this->discountPercent = 0;
         if ((0 != $specialPrice || 0 != $salePrice) && 0 != $basePrice) {
             if (0 != $salePrice) {
                 $this->discountPercent = number_format(100 - $salePrice / $basePrice * 100, Runtime::getSettings()->get('discountDecimals'));
             } else {
                 $this->discountPercent = number_format(100 - $specialPrice / $basePrice * 100, Runtime::getSettings()->get('discountDecimals'));
             }
         }
     }
 }
Beispiel #18
0
 /**
  * Get the download filesize.
  *
  * @return long The filesize.
  */
 public function getFileSize()
 {
     return filesize(Runtime::getSettings()->get('downloadBaseDir') . '/' . $this->filename);
 }
 /**
  * Set up.
  */
 public function setUp()
 {
     parent::setUp();
     // all tests assume this
     Runtime::getSettings()->set('zenmagick.mvc.resultlist.defaultPagination', 10);
 }
Beispiel #20
0
 /**
  * Get the language id.
  *
  * @return int The current language id.
  */
 public function getLanguageId()
 {
     $languageId = $this->get('languages_id');
     return null !== $languageId ? (int) $languageId : (int) Runtime::getSettings()->get('storeDefaultLanguageId');
 }
 /**
  * Test approve review.
  */
 public function testApproveReview()
 {
     $reviewService = $this->get('reviewService');
     $account = $this->get('accountService')->getAccountForId(1);
     if (null != $account) {
         $review = Beans::getBean('ZenMagick\\StoreBundle\\Entity\\Catalog\\Review');
         $review->setProductId(3);
         $review->setRating(4);
         $review->setLanguageId(1);
         $review->setText('some foo');
         Runtime::getSettings()->set('isApproveReviews', true);
         $newReview = $reviewService->createReview($review, $account, 1);
         $this->assertTrue(0 != $newReview->getId());
         // make sure it is *not* available via the service
         $found = false;
         foreach ($reviewService->getReviewsForProductId(3, 1) as $review) {
             if ($review->getId() == $newReview->getId()) {
                 $found = true;
                 break;
             }
         }
         $this->assertFalse($found, '%s new review with id: ' . $newReview->getId() . ' is available!');
     } else {
         $this->markTestIncomplete('no test account found');
     }
 }
Beispiel #22
0
 /**
  * Create new instance.
  */
 public function __construct()
 {
     parent::__construct();
     $this->firstName = '';
     $this->lastName = '';
     $this->dob = null;
     $this->nickName = '';
     $this->gender = '';
     //$this->email = null;
     $this->phone = '';
     $this->fax = null;
     $this->emailFormat = 'TEXT';
     $this->referral = '';
     $this->defaultAddressId = 0;
     $this->password = null;
     $this->authorization = Runtime::getSettings()->get('defaultCustomerApproval');
     $this->newsletter = false;
     $this->salt = null;
     $this->globalSubscriber = false;
     $this->subscribedProducts = null;
     $this->type = self::REGISTERED;
     $this->priceGroupId = 0;
     $this->authorization = Accounts::AUTHORIZATION_ENABLED;
     $this->payPalPayerId = '';
     $this->payPalEc = 0;
 }
Beispiel #23
0
 /**
  * Check stock.
  *
  * @param boolean messages Optional flag to enable/hide messages related to stock checking; default is <code>true</code>.
  * @return boolean <code>true</code> if the stock check was sucessful (or disabled).
  */
 public function checkStock($messages = true)
 {
     if (Runtime::getSettings()->get('isEnableStock') && $this->shoppingCart->hasOutOfStockItems()) {
         $flashBag = $this->container->get('session')->getFlashBag();
         if (Runtime::getSettings()->get('isAllowLowStockCheckout')) {
             if ($messages) {
                 $flashBag->warn('Products marked as "Out Of Stock" will be placed on backorder.');
             }
             return true;
         } else {
             if ($messages) {
                 $flashBag->error('The shopping cart contains products currently out of stock. To checkout you may either lower the quantity or remove those products from the cart.');
             }
             return false;
         }
     }
     return true;
 }
Beispiel #24
0
 /**
  * Get dashboard config.
  *
  * @param int adminId The admin id.
  * @return array config map.
  */
 public function getConfig($adminId)
 {
     $config = array();
     $dashboard = $this->container->get('adminUserPrefService')->getPrefForName($adminId, 'dashboard');
     if (empty($dashboard)) {
         $dashboard = Runtime::getSettings()->get('apps.store.dashboad.default');
     }
     $obj = json_decode($dashboard);
     foreach ($obj as $name => $value) {
         $config[$name] = $value;
     }
     // and again, just in case
     $config = array_merge(array('layout' => "col2l", 'widgets' => array()), $config);
     return $config;
 }