質問
私は製品の特別価格に時間を設定しようとしています。 3/20/2013 11am EST
に 4/20/2013 10:59am EST
)、しかし、私は現れたり保存したりする時間を得ることができません。
管理者に時間を入力すると(たとえば、 03/20/2013 11:00:00
)、それは常に表示されます 00:00:00
データベース内。カレンダーウィジェットに時間を表示できるように、管理者を更新する必要はありません。むしろ、時間をかけたら保存する必要があります。
解決
これは深刻なマゼントのバグだと思います。special_price_from
バックエンドモデルがあります Mage_Catalog_Model_Product_Attribute_Backend_Startdate
(それは拡張されます Mage_Eav_Model_Entity_Attribute_Backend_Datetime
) と special_price_to
バックエンドモデルがあります Mage_Eav_Model_Entity_Attribute_Backend_Datetime
.
これらの属性のいずれかを保存するたびに、この方法は呼び出されます Mage_Eav_Model_Entity_Attribute_Backend_Datetime::beforeSave($object)
。また、カレンダーは日付を国際形式で送信しないため、メソッドのコードのこのセクションに表示されます Mage_Eav_Model_Entity_Attribute_Backend_Datetime::formatDate($date)
:
$date = Mage::app()->getLocale()->date($date,
Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
null, false
);
これにより、時間の部分がストリップされます。回避策は、このコードを変更することです
$date = Mage::app()->getLocale()->date($date,
Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT. ' HH:mm:ss'),
null, false
);
(ローカルフォルダーにファイルをコピーします。他のクラスが拡張されているため、このクラスをオーバーライドする他の方法はありません)これにより、データベースの時間も節約できますが、他にも問題があります。製品を編集するときにデータベースに時間が正しく保存されたとしても、日付はまだ時間なしで表示され、他の時間を節約すると、病気が再び消えます。
このためには、DateTime属性のレンダラーを変更する必要があります。
そして、ここが私が立ち往生した場所です。たぶんあなたはそれをする方法についてのアイデアを持っています。見つけたら、答えを編集して説明します。
結論として、あなたが望むことをするのはそれほど簡単ではなく、それはマゼントに提起されるべき深刻な問題です。
編集
わかりました このリンク. 。コアの変更が含まれていると思いますが、お勧めしません。ただし、変更するために必要なファイルをコピーできます local
フォルダ。
他のヒント
うんざりして、この問題でほぼ1週間を失いました!!しかし、この投稿は解決策を指摘しました。つまり、テーブル「EAV_ATTRIBUTE」に移動し、「FrontEnd_Input」値を「日付」から「DateTime」に変更し、バックエンドにカレンダーウィジェットを変更できることを発見した後、時間と分を表示します(および値を受け入れるための入力フィールド)。
しかし、その後、マゼントは時刻を節約しなかったので...
ファイルアプリ/コード/コア/mage/eav/model/entity/attribute/backetime/datetime.phpをローカルフォルダー(App/code/local/mage/eav/model/entity/attribute/backend)にコピーし、変更しました次のように:
44行目の代替品:
try {
$value = $this->formatDate($object->getData($attributeName), $attributeFrontendInput);
これ:
try {
$attributeFrontendInput = $this->getAttribute()->getFrontendInput();
$value = $this->formatDate($object->getData($attributeName), $attributeFrontendInput);
(ここでは、属性frontend_inputモデル、つまり「日付」または「datetime」などを取得してから、formatdate関数に渡します)
次に、コードの後半のformatdate関数で、関数ヘッダーのパラメーターリストに新しい2番目のパラメーターを受け入れると、変数$ feinput
public function formatDate($date, $feInput)
そして、87行の代わりに:
$date = Mage::app()->getLocale()->date($date,
Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
null, false
);
これ:
if ($feInput == 'datetime') {
$date = Mage::app()->getLocale()->date($date,
Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
null, false
);
} else {
$date = Mage::app()->getLocale()->date($date,
Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
null, false
);
}
ここでは、$ feinput変数をテストし、入力モデルが「DateTime」に等しい場合、Magento Core CodeBaseのGetDateTimeFormat関数を使用します。
誰かがこれで数営業日をspareしまないかもしれないことを願っています。 Stack Exchangeのすべての男と女の子に感謝します!!
編集:
これは、Magento BackEndからDateTime値を正しく入力および保存できるためだけです。 DateTime値が正しくチェックされ、フロントエンドで処理されるさまざまなポイントで処理されることは、別のストーリーです...
彼の友人に加えて、マリウスはHTML値を時間に返すために投稿しました。次の変更を行うために必要です。
これを変える:
$html = sprintf(
'<input name="%s" id="%s" value="%s" %s style="width:110px !important;" />'
.' <img src="%s" alt="" class="v-middle" id="%s_trig" title="%s" style="%s" />',
$this->getName(), $this->getHtmlId(), $this->_escape($this->getValue()), $this->serialize($this->getHtmlAttributes()),
$this->getImage(), $this->getHtmlId(), 'Select Date', ($this->getDisabled() ? 'display:none;' : '')
);
それが理由です:
$html = sprintf(
'<input name="%s" id="%s" value="%s" %s style="width:110px !important;" />'
.' <img src="%s" alt="" class="v-middle" id="%s_trig" title="%s" style="%s" />',
$this->getName(), $this->getHtmlId(), $this->_escape($this->getValue($outputFormat)), $this->serialize($this->getHtmlAttributes()),
$this->getImage(), $this->getHtmlId(), 'Select Date', ($this->getDisabled() ? 'display:none;' : '')
);
つまり、変更 $outputFormat
getValue
働き。
これはうまくいきました。お役に立てれば。
これで5時間費やしたところです(マリウスの答えを組み合わせて)
ファイル: lib varien data form element data.php
私のロケールのみで、それを自分に変更します関数を追加します:
public function getRawMysqlDateFormat ($value) {
if (empty($this->_value)) {
return null;
}
$new_date = explode(" ", $value);
//2017年4月1日 下午4:16:16
$str_to_replace1 = array("年","月");
$str_to_replace2 = "日";
$new_date_part1 = str_replace($str_to_replace1, "-", $new_date[0]);
$new_date_part1 = str_replace($str_to_replace2, "", $new_date_part1);
$new_date_part2 = explode(":", $new_date[1]);
$hour = "";
$min = $new_date_part2[1];
$sec = $new_date_part2[2];
if (stripos($new_date_part2[0], "下午") !== false) {
$temp = str_replace("下午", "", $new_date_part2[0]);
$hour = $temp+12;
} else {
$temp = str_replace("上午", "", $new_date_part2[0]);
$hour = $new_date_part2[0];
}
return $new_date_part1.' '.$hour.':'.$min.':'.$sec;
}
変化する:
public function getElementHtml()
{
$this->addClass('input-text');
$html = sprintf(
'<input name="%s" id="%s" value="%s" %s style="width:110px !important;" />'
.' <img src="%s" alt="" class="v-middle" id="%s_trig" title="%s" style="%s" />',
$this->getName(), $this->getHtmlId(), $this->getRawMysqlDateFormat($this->_value), $this->serialize($this->getHtmlAttributes()),
$this->getImage(), $this->getHtmlId(), 'Select Date', ($this->getDisabled() ? 'display:none;' : '')
);
$outputFormat = $this->getFormat();
if (empty($outputFormat)) {
throw new Exception('Output format is not specified. Please, specify "format" key in constructor, or set it using setFormat().');
}
$displayFormat = Varien_Date::convertZendToStrFtime($outputFormat, true, (bool)$this->getTime());
$test = $this->getRawMysqlDateFormat($this->_value);
$html .= sprintf('
<script type="text/javascript">
//<![CDATA[
Calendar.setup({
inputField: "%s",
ifFormat: "%s",
showsTime: "true",
button: "%s_trig",
align: "Bl",
singleClick : true
});
//]]>
</script>',
$this->getHtmlId(), "%Y-%m-%d %H:%M:%S",
$this->getTime() ? 'true' : 'false', $this->getHtmlId()
);
$html .= $this->getAfterElementHtml();
return $html;
}