Beispiel #1
0
function renderVariation($variation, $i)
{
    if (!ProductSpecification::model()->findByPk(1)) {
        return false;
    }
    if (!$variation) {
        $variation = new ProductVariation();
        $variation->specification_id = 1;
    }
    $str = '<tr> <td>';
    $str .= CHtml::dropDownList("Variations[{$i}][specification_id]", $variation->specification_id, CHtml::listData(ProductSpecification::model()->findall(), "id", "title"), array('empty' => '-'));
    $str .= '</td> <td>';
    $str .= CHtml::textField("Variations[{$i}][title]", $variation->title);
    $str .= '</td> <td>';
    // Price adjustion
    $str .= CHtml::dropDownList("Variations[{$i}][sign_price]", $variation->price_adjustion >= 0 ? '+' : '-', array('+' => '+', '-' => '-'));
    $str .= '</td> <td>';
    $str .= CHtml::textField("Variations[{$i}][price_adjustion]", abs($variation->price_adjustion), array('size' => 5));
    // Weight adjustion
    $str .= '</td> <td>';
    $str .= CHtml::dropDownList("Variations[{$i}][sign_weight]", $variation->weight_adjustion >= 0 ? '+' : '-', array('+' => '+', '-' => '-'));
    $str .= '</td> <td>';
    $str .= CHtml::textField("Variations[{$i}][weight_adjustion]", abs($variation->weight_adjustion), array('size' => 5));
    $str .= '</td> <td>';
    for ($j = -10; $j <= 10; $j++) {
        $positions[$j] = $j;
    }
    $str .= CHtml::dropDownList("Variations[{$i}][position]", $variation->position, $positions);
    $str .= '</td></tr>';
    return $str;
}
Beispiel #2
0
function getSpecifications($position)
{
    $string = '<table class="specifications">';
    foreach ($position->getSpecifications() as $key => $specification) {
        if ($model = ProductSpecification::model()->findByPk($key)) {
            if ($model->input_type == 'textfield') {
                $title = $model->title;
                $value = $specification[0];
            } else {
                $title = $model->title;
                $productvariation = ProductVariation::model()->findByPk($specification[0]);
                if ($productvariation) {
                    $value = $productvariation->title;
                } else {
                    $value = '';
                }
            }
        } else {
            if ($key == 'image') {
                $title = Shop::t('Filename');
                $value = $specification;
            }
        }
        $string .= sprintf('<tr><td>%s</td><td>%s</td></tr>', @$title, @$value);
    }
    $string .= '</table>';
    return $string;
}
 public function actionCreate()
 {
     if (!is_numeric($_POST['amount']) || $_POST['amount'] <= 0) {
         Shop::setFlash(Shop::t('Illegal amount given'));
         $this->redirect(array('//shop/products/view', 'id' => $_POST['product_id']));
     }
     if (isset($_POST['Variations'])) {
         foreach ($_POST['Variations'] as $key => $variation) {
             $specification = ProductSpecification::model()->findByPk($key);
             if ($specification->required && $variation[0] == '') {
                 Shop::setFlash(Shop::t('Please select a {specification}', array('{specification}' => $specification->title)));
                 $this->redirect(array('//shop/products/view', 'id' => $_POST['product_id']));
             }
         }
     }
     $cart = Shop::getCartContent();
     // remove potential clutter
     if (isset($_POST['yt0'])) {
         unset($_POST['yt0']);
     }
     if (isset($_POST['yt1'])) {
         unset($_POST['yt1']);
     }
     $cart[] = $_POST;
     Shop::setCartcontent($cart);
     Shop::setFlash(Shop::t('The product has been added to the shopping cart'));
     $this->redirect(array('//shop/products/index'));
 }
Beispiel #4
0
 protected function postProcessData()
 {
     ProductPrice::loadPricesForRecordSetArray($this->data);
     ProductSpecification::loadSpecificationForRecordSetArray($this->data, true);
     Product::loadCategoryPathsForArray($this->data);
     foreach ($this->data as $key => $product) {
         $this->data[$key]['name_lang_utf8'] = $this->getFixedUtf8($product['name_lang']);
         $this->data[$key]['shortDescription_lang_utf8'] = $this->getFixedUtf8($product['shortDescription_lang']);
         $this->data[$key]['name_lang_safe'] = $this->getSafeEncoding($product['name_lang']);
         $this->data[$key]['shortDescription_lang_safe'] = $this->getSafeEncoding($product['shortDescription_lang']);
     }
 }
Beispiel #5
0
 public function process()
 {
     $this->application->getRouter()->removeAutoAppendVariable('currency');
     if (!$this->response instanceof ActionResponse) {
         return;
     }
     $products = $this->response->get('products');
     $parents = $variations = array();
     foreach ($products as $key => $product) {
         if ($product['parentID']) {
             $parents[$product['parentID']] = true;
             $variations[$key] = $product;
         }
     }
     if (!$parents) {
         return;
     }
     $loadedParents = array();
     foreach (ActiveRecordModel::getRecordSetArray('Product', select(in(f('Product.ID'), array_keys($parents))), array('Manufacturer', 'DefaultImage' => 'ProductImage', 'Category')) as $parent) {
         $loadedParents[$parent['ID']] = $parent;
     }
     ProductSpecification::loadSpecificationForRecordSetArray($loadedParents);
     ProductPrice::loadPricesForRecordSetArray($loadedParents);
     foreach ($products as $key => $product) {
         if ($product['parentID']) {
             $parent = $loadedParents[$product['parentID']];
             foreach ($parent as $field => $value) {
                 if (empty($product[$field])) {
                     $product[$field] = $parent[$field];
                 }
             }
             foreach (array('price_USD', 'price_CAD', 'formattedPrice', 'formattedListPrice') as $field) {
                 if (isset($parent[$field])) {
                     $product[$field] = $parent[$field];
                 }
             }
             ///var_dump($parent);exit;
             $products[$key] = $product;
         }
     }
     ProductSet::loadVariationsForProductArray($variations);
     foreach ($variations as $key => $variation) {
         $vars = array();
         foreach ($variation['variationTypes'] as $type) {
             $vars[] = $type['name_lang'];
         }
         if ($vars) {
             $products[$key]['name_lang'] .= ' (' . implode(' / ', $vars) . ')';
         }
     }
     $this->response->set('products', $products);
 }
Beispiel #6
0
 public function listSpecifications()
 {
     if (!($specs = $this->getSpecifications())) {
         return '';
     }
     $str = '(';
     foreach ($specs as $key => $specification) {
         if ($model = ProductSpecification::model()->findByPk($key)) {
             if ($model->input_type == 'textfield') {
                 $value = $specification[0];
             } else {
                 $value = @ProductVariation::model()->findByPk($specification[0])->title;
             }
         }
         $str .= $model->title . ': ' . $value . ', ';
     }
     $str = substr($str, 0, -2);
     $str .= ')';
     return $str;
 }
 public function actionCreate()
 {
     if (!is_numeric($_POST['amount']) || $_POST['amount'] <= 0) {
         Shop::setFlash(Shop::t('Illegal amount given'));
         $this->redirect(array('//shop/products/view', 'id' => $_POST['product_id']));
     }
     if (isset($_POST['Variations'])) {
         foreach ($_POST['Variations'] as $key => $variation) {
             $specification = ProductSpecification::model()->findByPk($key);
             if ($specification->required && $variation[0] == '') {
                 Shop::setFlash(Shop::t('Please select a {specification}', array('{specification}' => $specification->title)));
                 $this->redirect(array('//shop/products/view', 'id' => $_POST['product_id']));
             }
         }
     }
     if (isset($_FILES)) {
         foreach ($_FILES as $variation) {
             $target = Shop::module()->uploadedImagesFolder . '/' . $variation['name'];
             if ($variation['tmp_name'] == '') {
                 Shop::setFlash(Shop::t('Please select a image from your hard drive'));
                 $this->redirect(array('//shop/shoppingCart/view'));
             }
             if (move_uploaded_file($variation['tmp_name'], $target)) {
                 $_POST['Variations']['image'] = $target;
             }
         }
     }
     $cart = Shop::getCartContent();
     // remove potential clutter
     if (isset($_POST['yt0'])) {
         unset($_POST['yt0']);
     }
     if (isset($_POST['yt1'])) {
         unset($_POST['yt1']);
     }
     $cart[] = $_POST;
     Shop::setCartcontent($cart);
     Shop::setFlash(Shop::t('The product has been added to the shopping cart'));
     $this->redirect(array('//shop/shoppingCart/view'));
 }
Beispiel #8
0
 public static function sortAttributesByHandle(&$array)
 {
     return ProductSpecification::sortAttributesByHandle('ProductSpecification', $array);
 }
Beispiel #9
0
 public function getWeight($variations = null, $amount = 1)
 {
     $spec = ProductSpecification::model()->findByPk(Shop::module()->weightSpecificationId);
     $weight = 0;
     if ($spec) {
         $specs = json_decode($this->specifications, true);
         if (isset($specs[$spec->title])) {
             $weight += $specs[$spec->title];
         }
     }
     if ($variations) {
         foreach ($variations as $key => $variation) {
             if (is_array($variation)) {
                 $variation = $variation[0];
             }
             if (is_numeric($variation)) {
                 $weight += @ProductVariation::model()->findByPk($variation)->getWeightAdjustion();
             }
         }
     }
     return (double) ($weight *= $amount);
 }
Beispiel #10
0
 public function upSellBlock()
 {
     // upsell products
     $upsell = $this->getRelatedProducts($this->product, 1);
     foreach ($upsell as $key => $group) {
         foreach ($upsell[$key] as $i => &$prod) {
             $spec[] =& $upsell[$key][$i];
         }
     }
     if (count($upsell)) {
         ProductSpecification::loadSpecificationForRecordSetArray($spec);
     }
     $response = new BlockResponse();
     $response->set('upsell', $upsell);
     return $response;
 }
Beispiel #11
0
 protected function processDataArray($productArray, $displayedColumns)
 {
     // load price data
     ProductPrice::loadPricesForRecordSetArray($productArray, false);
     // load child products
     //		if (isset($displayedColumns['Product.parentID']))
     //{
     ProductSet::loadVariationTypesForProductArray($productArray);
     ProductSet::loadChildrenForProductArray($productArray);
     //}
     ProductSpecification::loadSpecificationForRecordSetArray($productArray, true);
     foreach ($productArray as &$product) {
         if (!empty($product['children'])) {
             foreach ($product['children'] as &$child) {
                 if (!empty($product['attributes'])) {
                     $child['attributes'] = $product['attributes'];
                 }
                 if (!empty($product['Manufacturer'])) {
                     $child['Manufacturer'] = $product['Manufacturer'];
                 }
                 foreach (array('definedPrices', 'definedListPrices', 'price_USD', 'price_CAD', 'listPrice_USD', 'listPrice_CAD') as $key) {
                     if (!empty($product[$key])) {
                         $child[$key] = $product[$key];
                     }
                 }
                 foreach ($child as $key => $value) {
                     if (empty($value) && !empty($product[$key])) {
                         $child[$key] = $product[$key];
                     }
                 }
                 $variation = null;
                 if (!empty($child['variationValues'])) {
                     $variation = array_shift($child['variationValues']);
                 }
                 $name = $child['name'];
                 $child['URL'] = $product['URL'];
                 $child['name_lang'] = $name . ' ' . $child['sku'];
                 $child['xParent'] = $child['Parent'];
                 unset($child['Parent']);
                 $child['URL'] = $this->router->createFullUrl(createProductUrl(array('product' => $child), $this->application));
                 $child['Parent'] = $child['xParent'];
                 $child['name'] = $name;
                 if ($variation) {
                     $child['name'] .= ' (' . $variation . ')';
                     $child['name_lang'] = $child['name'];
                 }
                 $child['id'] = $child['ID'];
             }
             $product['URL'] = $this->router->createFullUrl(createProductUrl(array('product' => $product), $this->application));
             if (empty($product['ProductImage']['ID'])) {
                 if (!empty($product['children'][0]['ProductImage'])) {
                     $product['ProductImage'] = $product['children'][0]['ProductImage'];
                     $product['DefaultImage'] = $product['children'][0]['DefaultImage'];
                 }
             }
         }
         $product['id'] = $product['ID'];
     }
     $defCurrency = $this->application->getDefaultCurrencyCode();
     foreach ($productArray as &$product) {
         foreach ($this->getUserGroups() as $groupID => $groupName) {
             if (isset($product['priceRules'][$defCurrency][1][$groupID])) {
                 $product['GroupPrice'][$groupID] = $product['priceRules'][$defCurrency][1][$groupID];
             }
         }
     }
     return $productArray;
 }
Beispiel #12
0
 protected function processDataArray($productArray, $displayedColumns)
 {
     // load specification data
     foreach ($displayedColumns as $column => $type) {
         list($class, $field) = explode('.', $column, 2);
         if ('specField' == $class) {
             ProductSpecification::loadSpecificationForRecordSetArray($productArray, true);
             break;
         }
     }
     // load price data
     ProductPrice::loadPricesForRecordSetArray($productArray, false);
     // load child products
     if (isset($displayedColumns['Product.parentID'])) {
         ProductSet::loadVariationTypesForProductArray($productArray);
         ProductSet::loadChildrenForProductArray($productArray);
     }
     $defCurrency = $this->application->getDefaultCurrencyCode();
     foreach ($productArray as &$product) {
         foreach ($this->getUserGroups() as $groupID => $groupName) {
             if (isset($product['priceRules'][$defCurrency][1][$groupID])) {
                 $product['GroupPrice'][$groupID] = $product['priceRules'][$defCurrency][1][$groupID];
             }
         }
     }
     return $productArray;
 }
Beispiel #13
0
echo Shop::t('Shopping cart');
?>
</h2>


<?php 
if ($products) {
    echo '<table cellpadding="0" cellspacing="0" class="shopping_cart">';
    printf('<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th style="width:60px;">%s</th><th style="width:60px;">%s</th><th>%s</th></tr>', Shop::t('Image'), Shop::t('Amount'), Shop::t('Product'), Shop::t('Variation'), Shop::t('Price Single'), Shop::t('Sum'), Shop::t('Actions'));
    //var_dump($products);die();
    foreach ($products as $position => $product) {
        if ($model = Products::model()->findByPk($product['product_id'])) {
            $variations = '';
            if (isset($product['Variations'])) {
                foreach ($product['Variations'] as $specification => $variation) {
                    if ($specification = ProductSpecification::model()->findByPk($specification)) {
                        if ($specification->input_type == 'textfield') {
                            $variation = $variation[0];
                        } else {
                            $variation = ProductVariation::model()->findByPk($variation);
                        }
                        if (Shop::module()->allowPositionLiveChange) {
                            if ($specification->input_type == 'select') {
                                $name = sprintf('variation_%s_%s', $position, $specification->id);
                                $variations .= CHtml::radioButtonList($name, $variation->id, ProductVariation::listData($variation->getVariations(), true));
                                Yii::app()->clientScript->registerScript($name, "\r\n\t\t\t\t\t\t\t\t\t\t\$('[name=\"" . $name . "\"]').click(function(){\r\n\t\t\t\t\t\t\t\t\t\$.ajax({\r\n\t\t\t\t\t\t\t\t\t\t\t'url' : '" . CController::createUrl('//shop/shoppingCart/updateVariation') . "',\r\n\t\t\t\t\t\t\t\t\t\t\t'type' : 'POST',\r\n\t\t\t\t\t\t\t\t\t\t\t'data' : \$(this),\r\n\t\t\t\t\t\t\t\t\t\t\terror: function() {\r\n\t\t\t\t\t\t\t\t\t\t\t\$('#amount_" . $position . "').css('background-color', 'red');\r\n\t\t\t\t\t\t\t\t\t\t\t},\r\n\t\t\t\t\t\t\t\t\t\t\tsuccess: function(result) {\r\n\t\t\t\t\t\t\t\t\t\t\t\$('.amount_" . $position . "').css('background-color', 'lightgreen');\r\n\t\t\t\t\t\t\t\t\t\t\t\$('.widget_amount_" . $position . "').css('background-color', 'lightgreen');\r\n\t\t\t\t\t\t\t\t\t\t\t\$('.widget_amount_" . $position . "').html(\$('.amount_" . $position . "').val());\r\n\t\t\t\t\t\t\t\t\t\t\t\$('.price_" . $position . "').html(result);\t\r\n\t\t\t\t\t\t\t\t\t\t\t\$('.price_single_" . $position . "').load('" . $this->createUrl('//shop/shoppingCart/getPriceSingle?position=' . $position) . "');\r\n\t\t\t\t\t\t\t\t\t\t\t\$('.price_total').load('" . $this->createUrl('//shop/shoppingCart/getPriceTotal') . "');\r\n\t\t\t\t\t\t\t\t\t\t\t\$('.shipping_costs').load('" . $this->createUrl('//shop/shoppingCart/getShippingCosts') . "');\r\n\r\n\t\t\t\t\t\t\t\t\t\t\t},\r\n\t\t\t\t\t\t\t\t\t\t\t});\r\n\t\t\t\t\t\t\t});\r\n\r\n\t\t\t\t\t\t\t\t\t\t\$('input:checked').trigger('click');\r\n\t\t\t\t\t\t\t\t\t\t");
                                $variations .= '<br />';
                            }
                        } else {
                            $variations .= $specification . ': ' . $variation . '<br />';
                        }
Beispiel #14
0
 protected function productListBlock()
 {
     // get list items
     $f = new ARSelectFilter(new EqualsCond(new ARFieldHandle('ProductList', 'categoryID'), $this->getCategory()->getID()));
     $f->setOrder(new ARFieldHandle('ProductList', 'position'));
     $f->setOrder(new ARFieldHandle('ProductListItem', 'productListID'));
     $f->setOrder(new ARFieldHandle('ProductListItem', 'position'));
     $items = array();
     foreach (ActiveRecordModel::getRecordSetArray('ProductListItem', $f, array('ProductList', 'Product', 'ProductImage')) as $item) {
         $entry =& $item['Product'];
         $entry['ProductList'] =& $item['ProductList'];
         $items[] =& $entry;
     }
     ProductSpecification::loadSpecificationForRecordSetArray($items);
     ProductPrice::loadPricesForRecordSetArray($items);
     // sort by lists
     $lists = array();
     foreach ($items as &$item) {
         $lists[$item['ProductList']['ID']][] =& $item;
     }
     $response = new BlockResponse();
     $response->set('lists', $lists);
     return $response;
 }
Beispiel #15
0
 private function getComparedProducts()
 {
     $filter = Category::getRootNode()->getProductFilter(select(IN('Product.ID', $this->getComparedProductIDs())));
     $products = ActiveRecord::getRecordSetArray('Product', $filter, array('Category', 'ProductImage'));
     ProductSpecification::loadSpecificationForRecordSetArray($products, true);
     ProductPrice::loadPricesForRecordSetArray($products);
     return $products;
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = ProductSpecification::model()->findByPk((int) $id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }