Esempio n. 1
0
 /**
  *
  * @param array $data
  * @return Axis_Db_Table_Row
  */
 public function save(array $data)
 {
     $row = $this->getRow($data);
     //before save
     $row->rate = Axis_Locale::getNumber($row->rate);
     if ($row->code === Axis::config('locale/main/currency') && $row->rate != 1) {
         //            throw new Axis_Exception(
         Axis::message()->addError(Axis::translate('locale')->__('Base currency rate should be 1.00'));
         $row->rate = 1;
     }
     if (empty($row->format)) {
         $row->format = new Zend_Db_Expr('NULL');
     }
     //end before save
     $row->save();
     return $row;
 }
Esempio n. 2
0
 /**
  * Add new product or product variation to shopping cart
  *
  * @param int $productId
  * @param array $modifierOptions
  * @param array $variationOptions
  * @param array $quantity [optional]
  * @return mixed int|bool
  */
 public function add($productId, $modifierOptions, $variationOptions, $quantity = false)
 {
     $product = Axis::single('catalog/product')->find($productId)->current();
     if (!$product instanceof Axis_Catalog_Model_Product_Row) {
         Axis::message()->addError(Axis::translate('catalog')->__('Product not found'));
         return false;
     }
     $stockRow = $product->getStockRow();
     if (!$quantity) {
         $quantity = $stockRow->min_qty_allowed ? $stockRow->min_qty_allowed : 1;
     }
     if (!$stockRow->decimal) {
         $quantity = floor($quantity);
     }
     $shoppingCartProductRow = array('shopping_cart_id' => $this->getCartId(), 'product_id' => $productId, 'quantity' => $quantity, 'final_price' => 0, 'final_weight' => 0, 'variation_id' => 0);
     $variationId = $product->getVariationIdByVariationOptions($variationOptions);
     if (false === $variationId) {
         Axis::message()->addError(Axis::translate('checkout')->__('Fill all variation options please'));
         return false;
     }
     $shoppingCartProductRow['variation_id'] = $variationId;
     if (!$stockRow->canAddToCart($quantity, $variationId)) {
         return false;
     }
     $modifierAttributes = Axis::single('catalog/product_attribute')->getAttributesByModifiers($product->id, $modifierOptions);
     if (false === $modifierAttributes) {
         return false;
     }
     $variationAttributes = Axis::single('catalog/product_attribute')->getAttributesByVariation($variationId, $variationOptions);
     if (false === $variationAttributes) {
         return false;
     }
     $attributes = $modifierAttributes + $variationAttributes;
     Axis::message()->addSuccess(Axis::translate('checkout')->__('Product was successfully added to your shopping cart'));
     // Check for clon exists
     if (false !== ($clon = $this->_getClon($productId, $attributes))) {
         $this->updateItem($clon['id'], $clon['quantity'] + Axis_Locale::getNumber($quantity));
         return true;
     }
     // Insert product
     $shoppingCartProductRow['final_price'] = $product->getPrice(array_keys($attributes));
     $shoppingCartProductRow['final_weight'] = $product->getWeight(array_keys($attributes));
     $shoppingCartProductId = Axis::single('checkout/cart_product')->insert($shoppingCartProductRow);
     // Insert attributes for this product
     $modelCartAttribute = Axis::single('checkout/cart_product_attribute');
     foreach ($attributes as $attributeId => $attributeValue) {
         $modelCartAttribute->insert(array('shopping_cart_product_id' => $shoppingCartProductId, 'product_attribute_id' => $attributeId, 'product_attribute_value' => $attributeValue));
     }
     Axis::dispatch('checkout_cart_add_product_success', array('product' => $product, 'attributes' => $attributes, 'quantity' => $quantity, 'cart_product_id' => $shoppingCartProductId));
     return $shoppingCartProductId;
 }
Esempio n. 3
0
 /**
  * Prepare data for table before save
  *
  * @param array $data
  * @return array
  */
 protected function _prepareDataForTable($data)
 {
     foreach ($this->info(self::METADATA) as $name => $values) {
         if (!isset($data[$name]) || $data[$name] instanceof Zend_Db_Expr) {
             continue;
         }
         if ('decimal' == $values['DATA_TYPE']) {
             $data[$name] = Axis_Locale::getNumber($data[$name]);
         }
     }
     return $data;
 }