Example #1
0
 /**
  * Update price indexes for recieved products
  *
  * @param array $products Keys are the product id
  * @return void
  */
 public function updateIndexesByProducts(array $products)
 {
     if (!count($products)) {
         return;
     }
     $ids = array_keys($products);
     $oldPricesTemp = $this->select('*')->where('product_id IN (?)', $ids)->fetchAll();
     $oldPrices = array();
     foreach ($oldPricesTemp as $oldPrice) {
         $oldPrices[$oldPrice['product_id']][] = $oldPrice;
     }
     $variationsTemp = Axis::model('catalog/product_variation')->select()->where('product_id IN (?)', $ids)->fetchAll();
     $variations = array();
     foreach ($variationsTemp as $variation) {
         $variations[$variation['product_id']][] = $variation;
     }
     foreach ($products as $product) {
         $variations[$product['id']][] = array('id' => 0, 'product_id' => $product['id'], 'quantity' => 0, 'price' => 0, 'price_type' => 'by', 'weight' => 0, 'weight_type' => 'by');
     }
     $modifiersTemp = Axis::model('catalog/product_attribute')->select('*')->joinInner('catalog_product_option', 'cpo.id = cpa.option_id', 'input_type')->where('cpa.product_id IN (?)', $ids)->where('cpa.modifier = 1')->where('cpa.variation_id = 0')->fetchAll();
     $modifiers = array();
     foreach ($modifiersTemp as $modifier) {
         $modifiers[$modifier['product_id']][] = $modifier;
     }
     $productToSites = Axis::model('catalog/product_category')->getSitesByProductIds($ids);
     $mDiscount = Axis::model('discount/discount');
     $discounts = $mDiscount->getApplicableDiscounts($ids, $mDiscount->getAllRules(true, false));
     $customerGroups = array_filter(array_keys(Axis_Collect_CustomerGroup::collect()));
     foreach ($products as $product) {
         if (!isset($productToSites[$product['id']])) {
             $this->delete('product_id = ' . $product['id']);
             continue;
         }
         $newPrices = $this->setProductData(array('id' => $product['id'], 'price' => $product['price'], 'site_ids' => $productToSites[$product['id']], 'customer_group_ids' => $customerGroups, 'modifiers' => isset($modifiers[$product['id']]) ? $modifiers[$product['id']] : array(), 'variations' => $variations[$product['id']], 'discounts' => isset($discounts[$product['id']]) ? $discounts[$product['id']] : array()))->getPriceIndexes();
         $oldAssocPrices = array();
         if (isset($oldPrices[$product['id']]) && count($oldPrices[$product['id']])) {
             foreach ($oldPrices[$product['id']] as $oldPrice) {
                 $oldAssocPrices[$oldPrice['id']] = $oldPrice;
             }
             $this->delete(Axis::db()->quoteInto('id IN (?)', array_keys($oldAssocPrices)));
         }
         foreach ($newPrices as $price) {
             $this->insert($price);
         }
         Axis::dispatch('catalog_product_price_update_after', array('product_data' => $product, 'new_price' => $newPrices, 'old_price' => $oldAssocPrices));
     }
 }
Example #2
0
 private function _initForm()
 {
     $this->view->sites = Axis_Collect_Site::collect();
     $this->view->customerGroups = Axis_Collect_CustomerGroup::collect();
     $this->view->manufactures = Axis_Collect_Manufacturer::collect();
     $languageId = Axis_Locale::getLanguageId();
     $this->view->categoryTrees = Axis::single('catalog/category')->select('*')->addName($languageId)->addKeyWord()->order('cc.lft')->fetchAllAndSortByColumn('site_id');
     $select = Axis::model('catalog/product_option_value')->select('*')->joinLeft('catalog_product_option_value_text', 'cpov.id = cpovt.option_value_id', 'name')->where('cpovt.language_id = ?', $languageId);
     $valuesetValues = array();
     foreach ($select->fetchAll() as $_row) {
         $valuesetValues[$_row['valueset_id']][$_row['id']] = $_row['name'];
     }
     $select = Axis::single('catalog/product_option')->select('*')->addNameAndDescription($languageId);
     $attributes = array();
     foreach ($select->fetchAll() as $_option) {
         if (isset($valuesetValues[$_option['valueset_id']])) {
             $attributes[$_option['id']] = array('name' => $_option['name'], 'option' => $valuesetValues[$_option['valueset_id']]);
         }
     }
     $this->view->attributes = $attributes;
 }
Example #3
0
 /**
  * Get info about discount + discount rules (condition)
  *
  * @return array
  */
 public function getCustomInfo()
 {
     $array = $this->toArray();
     $rules = Axis::single('discount/eav')->getRulesByDiscountId($this->id);
     if (isset($rules['conditions'])) {
         $array['conditions'] = $rules['conditions'];
     }
     if (isset($rules['category'])) {
         $array['category'] = $rules['category'];
     }
     if (isset($rules['productId'])) {
         $array['productId'] = $rules['productId'];
     }
     if (isset($rules['manufacture'])) {
         $array['manufacture'] = array_intersect($rules['manufacture'], array_keys(Axis_Collect_Manufacturer::collect()));
     }
     if (isset($rules['site'])) {
         $array['site_ids'] = array_intersect($rules['site'], array_keys(Axis_Collect_Site::collect()));
     }
     if (isset($rules['group'])) {
         $array['customer_group_ids'] = array_intersect($rules['group'], array_keys(Axis_Collect_CustomerGroup::collect()));
     }
     if (isset($rules['special'])) {
         $array['special'] = current($rules['special']);
     }
     if (isset($rules['optionId'])) {
         foreach ($rules['optionId'] as $optionId) {
             if (!isset($rules['option[' . $optionId . ']'])) {
                 continue;
             }
             foreach ($rules['option[' . $optionId . ']'] as $optionValueId) {
                 $array['attributes'][] = array('optionId' => $optionId, 'optionValueId' => $optionValueId);
             }
         }
     }
     return $array;
 }